﻿'Copyright ?1995-2007, Camstar Systems, Inc. All Rights Reserved.
'Description:流水卡打印
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:YangSJ
'create Date:2018-5-25
'Rewriter:
'Rewrite Date:
Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports Camstar.WebClient.FormsBuilder.WebForm
Imports Camstar.WebClient.WebServicesProxy.InSiteWebServices
Imports System.IO
Imports Camstar.WebClient.WebConstants
Imports BusinessRule.IBusiness
Imports BusinessRule.DTO
Imports BusinessRule.BusinessFactory
Imports BusinessRule.Common

Partial Class forms_shopfloor_uMESDocPrint_ContainerInfoPrintForm
    Inherits System.Web.UI.Page

    Private oIBusiness As uMESContainerInfoPrintIBusiness = uMESBusinessFactory.instance.GetContainerInfoPrintObject("LY_JX")
    Private m_CommonObj As uLMSCommonIBusiness = uMESBusinessFactory.instance.GetuLMSCommonObject
    Private strProductName As String
    Public htmlstr As String
    Public strHtmlTable As String
    Public strContainerName As String
    Public strMfgordername As String
    Private strContainerID As String
    Private isselfmfg As Boolean
    Private partCharacterType As String
    Private bomPersonMerge As String 'add:Wangjh 20180607 配套表人员是否合并
    Private startDate As String 'add:Wangjh 20180524
    Private strTechniqueEmp As String
    Private strPlanName As String
    Private wfFactoryName As String
    Private IsRotate As Boolean = False '是否旋转
    Private isBlank As Boolean = False '是否空白页
    Private conPrintType As Integer = "1" '1:工序执行检查 2:流水卡打印(入库只打干过的，在制情况只打当前工序之后) add:Wangjh 20230330
    Private isBomPrint As Boolean = False '是否配套表打印 add by zhangrj 20231121
    Private dtSubWorkflowstepList As DataTable '各子工艺工序热表批次号 add zhuan 2022.10.27
    Private strFinallyShowContainername As String = "" '打印最终显示的批次号 add zhunan 2023.1.17
    Private conRemark As String = "" '自动开卡标识 add by zhangrj 20240308
#Region "事件"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim conid As String = Request("ContainerId") '
            Dim printInfo As New Dictionary(Of String, String)
            Dim subWorkFlowNames As String = "" '子工艺Process_No
            'Dim isBlank As Boolean = False '是否空白页

            Dim wfIDAndProID As New Dictionary(Of String, String) '只有工艺和产品信息打印

            If conid = "" Then
                If IsNothing(Session("PrintInfo")) = False Then
                    printInfo = Session("PrintInfo")
                    Session.Remove("PrintInfo")
                    If printInfo.ContainsKey("ContainerIDForPrint") Then
                        conid = printInfo("ContainerIDForPrint")
                        If printInfo.ContainsKey("SubWorkFlowName") Then
                            subWorkFlowNames = printInfo("SubWorkFlowName")
                        End If
                        If printInfo.ContainsKey("IsBlank") Then '空白页打印
                            isBlank = True
                        End If
                        If printInfo.ContainsKey("IsRotate") Then
                            If printInfo("IsRotate") = "1" Then '旋转
                                IsRotate = True
                            End If
                        End If
                        If printInfo.ContainsKey("ConPrintType") Then
                            conPrintType = printInfo("ConPrintType")
                        End If
                        If printInfo.ContainsKey("IsBomPrint") Then
                            isBomPrint = True
                        End If
                    Else
                        wfIDAndProID = printInfo
                    End If
                    Session.Remove("PrintInfo")
                Else
                    Response.Write("<script type='text/javascript'>alert('缺少流水卡ID');window.close();</script>")
                    Return
                End If
            Else
                IsRotate = True
            End If

            strHtmlTable = String.Empty
            If wfIDAndProID.Count = 0 Then
                If String.IsNullOrWhiteSpace(subWorkFlowNames) Then
                    Excute(conid)
                Else '打印合并子工艺
                    Excute(conid, subWorkFlowNames)
                End If
            Else
                Excute(wfIDAndProID)
            End If

        End If
    End Sub
#End Region

#Region "方法"
    ''' <summary>
    ''' 执行流水卡生成
    ''' </summary>
    ''' <param name="conid"></param>
    ''' <remarks></remarks>
    Sub Excute(ByVal conid As String)
        If conid.Contains(",") Then
            For Each Str As String In conid.Split(",")
                If String.IsNullOrEmpty(Str) Then
                    Continue For
                End If
                strContainerID = Str 'add:Wangjh 2017-9-13
                'Dim subDt As DataTable = oIBusiness.GetContainerCurrentSubWorkflow(Str)
                'If subDt.Rows.Count > 0 Then
                '    iniPate(Str, subDt.Rows(0)("process_no"), isBlank)
                'Else
                '    iniPate(Str, isBlank)
                'End If
                iniPate(Str)
            Next
        Else
            strContainerID = conid 'add:Wangjh 2017-9-13
            'Dim subDt As DataTable = oIBusiness.GetContainerCurrentSubWorkflow(conid)
            'If subDt.Rows.Count > 0 Then
            '    iniPate(conid, subDt.Rows(0)("process_no"), isBlank)
            'Else
            '    iniPate(conid, isBlank)
            'End If
            iniPate(conid)
        End If
        If String.IsNullOrWhiteSpace(strHtmlTable) Then
            strHtmlTable = "<script>alert('无打印信息');</script>"
        End If
    End Sub

    ''' <summary>
    ''' 执行流水卡生成用于打印合并子工艺情况
    ''' </summary>
    ''' <param name="conid"></param>
    ''' <param name="subPdmWorkFlows"></param>
    ''' <remarks></remarks>
    Sub Excute(ByVal conid As String, ByVal subPdmWorkFlows As String)
        If conid.Contains(",") Then
            For Each Str As String In conid.Split(",")
                If String.IsNullOrEmpty(Str) Then
                    Continue For
                End If
                strContainerID = Str 'add:Wangjh 2017-9-13
                For Each padmSubwf As String In subPdmWorkFlows.Split(",")
                    If String.IsNullOrEmpty(padmSubwf) Then
                        Continue For
                    End If
                    iniPate(Str, padmSubwf)
                Next
            Next
        Else
            strContainerID = conid 'add:Wangjh 2017-9-13
            iniPate(conid, subPdmWorkFlows)
        End If
    End Sub

    ''' <summary>
    ''' 无批次信息，只有产品和工艺信息打印
    ''' </summary>
    ''' <param name="wfIDAndProID"></param>
    ''' <remarks></remarks>
    Sub Excute(ByVal wfIDAndProID As Dictionary(Of String, String))
        If wfIDAndProID("IsSelf") = 1 Then
            isselfmfg = True
        Else
            isselfmfg = False
        End If

        Dim PR = oIBusiness.GetWorkflowPrintView(wfIDAndProID)
        strProductName = wfIDAndProID("ProductName")
        PR.DBDataSet.Tables("dtMain").Rows(0)("ProductDesc") = wfIDAndProID("ProductDesc")
        Dim tPageCount As Integer = Math.Ceiling((PR.DBDataSet.Tables("dtContainerStep").Rows.Count + PR.DBDataSet.Tables("dtCheckItemList").Rows.Count + 5) / 25) 'modify by yuxj 25=>24
        PR.PageCount = tPageCount
        Dim strHtmlTitle As String = SetTableTitle(PR.PageCount, 1, 0, partCharacterType, startDate, "")
        Dim strHtmlTableMain As String = "" 'SetTableMain(PR, 0)
        strContainerID = ""
        strContainerName = ""
        strMfgordername = ""
        Dim strHtmlTableDetails As String = SetTableDetail(PR, 0)
        Dim strBomDetails = SetBomDetail(PR)
        strHtmlTable = String.Format("{0}{1}{2}{3}{4}", strHtmlTable, strHtmlTitle, strHtmlTableMain, strHtmlTableDetails, strBomDetails)

    End Sub

    ''' <summary>
    ''' 数据初始化
    ''' </summary>
    ''' <param name="strContainerID"></param>
    ''' <remarks></remarks>
    Private Sub iniPate(ByVal strContainerID As String)
        Dim dic As New Dictionary(Of String, String)
        dic.Add("Containerid", strContainerID)
        If Not String.IsNullOrWhiteSpace(Session("SubWorkFlowIDForPrint")) Then '子工艺查看流水卡
            ' dtContainerStep = oIBusiness.GetStepInfoByWorkFlowID(Session("SubWorkFlowIDForPrint").ToString)
            dic.Add("SubWorkFlowIDForPrint", Session("SubWorkFlowIDForPrint"))
            Session("SubWorkFlowIDForPrint") = Nothing
        End If

        If isBlank Then '打印空白页
            dic.Add("IsBlank", "0")
        End If

        dic.Add("ConPrintType", conPrintType)

        Dim PR As uMESProcessResult = oIBusiness.GetContainerPrintInfo(dic)
        '工艺员查询
        strTechniqueEmp = PR.DBDataSet.Tables("dtMain").Rows(0)("TECHNIQUEEMPLOYNAME").ToString
        '
        strProductName = PR.DBDataSet.Tables("dtMain").Rows(0)("productname").ToString()
        strPlanName = PR.DBDataSet.Tables("dtMain").Rows(0)("PlanFullName").ToString
        wfFactoryName = PR.DBDataSet.Tables("dtMain").Rows(0)("wffactoryname").ToString() '工艺分厂
        IniPrintInfo(PR, False)
    End Sub
    ''' <summary>
    ''' 数据初始化
    ''' </summary>
    Private Sub iniPate(ByVal strContainerID As String, ByVal subPDMWorkFlowname As String)

        Dim dic As New Dictionary(Of String, String)
        dic.Add("Containerid", strContainerID)
        dic.Add("PdmSubWf", subPDMWorkFlowname)
        If isBlank Then '打印空白页
            dic.Add("IsBlank", "0")
        End If
        Dim PR As uMESProcessResult = oIBusiness.GetContainerPrintInfoForSub(dic)
        wfFactoryName = PR.DBDataSet.Tables("dtMain").Rows(0)("wffactoryname").ToString() '工艺分厂
        strProductName = PR.DBDataSet.Tables("dtMain").Rows(0)("productname").ToString()
        '工艺员查询
        Dim subCheckTechnique As DataTable = oIBusiness.GetSubWorkflowCheckTechnique(dic)
        If subCheckTechnique.Rows.Count > 0 Then
            strTechniqueEmp = subCheckTechnique.Rows(0)("fullname").ToString
            strPlanName = subCheckTechnique.Rows(0)("planname").ToString
        End If
        '
        IniPrintInfo(PR, True)
    End Sub
    ''' <summary>
    ''' 填充打印信息
    ''' </summary>
    ''' <param name="PR"></param>
    ''' <remarks></remarks>
    Private Sub IniPrintInfo(ByVal PR As uMESProcessResult, ByVal IsSubWorkflow As Boolean)

        Dim tPageCount As Integer = Math.Ceiling((PR.DBDataSet.Tables("dtContainerStep").Rows.Count + PR.DBDataSet.Tables("dtCheckItemList").Rows.Count + 5) / 25) 'modify by yuxj 25=>24

        PR.PageCount = tPageCount
        Dim Originalqty = PR.DBDataSet.Tables("dtMain").Rows(0)("Originalqty").ToString()
        Dim conType As Integer = Val(PR.DBDataSet.Tables("dtMain").Rows(0)("CONTAINERTYPE").ToString())
        strMfgordername = PR.DBDataSet.Tables("dtMain").Rows(0)("Mfgordername").ToString()
        isselfmfg = If(PR.DBDataSet.Tables("dtMain").Rows(0)("isselfmfg").ToString() = "0", True, False)
        startDate = PR.DBDataSet.Tables("dtMain").Rows(0)("originalstartdate").ToString()
        Dim gys As String = GetDataValue(PR.DBDataSet.Tables("dtDataPoint"), "供应商", False)
        '产品特性 add:Wangjh 20150517
        partCharacterType = PR.DBDataSet.Tables("dtMain").Rows(0)("charactertype").ToString()
        If partCharacterType <> "关键件" And partCharacterType <> "重要件" Then
            partCharacterType = ""
        End If
        '自动开卡标识
        Dim dtDataPoint As DataTable = PR.DBDataSet.Tables("dtDataPoint")
        conRemark = GetDataValue(dtDataPoint, "自动开卡")
        If String.IsNullOrWhiteSpace(conRemark) Then
            conRemark = "手动开卡"
        Else
            If conRemark = "手动" Then
                conRemark = "一键开卡"
            ElseIf conRemark = "自动" Then
                conRemark = "自动开卡"
            Else
                conRemark = ""
            End If
        End If

        '显示批次后缀 add zhunan 2023.1.17
        Dim dtMain As DataTable = PR.DBDataSet.Tables("dtMain")
        Dim productName = dtMain.Rows(0)("Productname").ToString()
        Dim Containername = dtMain.Rows(0)("Containername").ToString()
        Dim customobjectitemsname = dtMain.Rows(0)("customobjectitemsname").ToString '批次后缀 add zhunan 2023.1.17
        If customobjectitemsname <> "" Then
            Dim strContainername = Containername.Replace(productName + "/", "")
            strFinallyShowContainername = String.Format("<del>{0}</del><br/>{1}", strContainername, strContainername + customobjectitemsname)
        Else
            strFinallyShowContainername = Containername.Replace(productName + "/", "")
        End If

        If isBomPrint Then '如果是配套表打印，只打印配套表
            strHtmlTable += SetBomDetailNew(PR)
            Exit Sub
        End If
        '
        Dim strHtmlTitle As String = SetTableTitle(PR.PageCount, 1, conType, partCharacterType, startDate, gys)
        Dim strHtmlTableMain As String = SetTableMain(PR, Originalqty)
        Dim strHtmlTableDetails As String = SetTableDetail(PR, Originalqty)
        Dim strBomDetails As String = ""
        Dim strMterialListItemInfo As String = "" 'add zhunan 2021.7.28
        If Originalqty = 1 Then 'creat:Wangjh 2017-6-22
            strBomDetails = SetBomDetailNew(PR)
            strMterialListItemInfo = SetMaterialListItemInfo(PR) 'add zhunan 2021.7.28
            'modify zhunan 2021.7.28
            'strHtmlTable = String.Format("{0}{1}{2}{3}{4}", strHtmlTable, strHtmlTitle, strHtmlTableMain, strHtmlTableDetails, strBomDetails)
            strHtmlTable = String.Format("{0}{1}{2}{3}{4}{5}", strHtmlTable, strHtmlTitle, strHtmlTableMain, strHtmlTableDetails, strBomDetails, strMterialListItemInfo)
        Else
            Dim strSplitInfo As String = SetSplitInfo(PR)
            strBomDetails = SetBomDetailNew(PR)
            strMterialListItemInfo = SetMaterialListItemInfo(PR) 'add zhunan 2021.7.28
            'modify zhunan 2021.7.28
            'strHtmlTable = String.Format("{0}{1}{2}{3}{4}{5}", strHtmlTable, strHtmlTitle, strHtmlTableMain, strHtmlTableDetails, strSplitInfo, strBomDetails)
            strHtmlTable = String.Format("{0}{1}{2}{3}{4}{5}{6}", strHtmlTable, strHtmlTitle, strHtmlTableMain, strHtmlTableDetails, strSplitInfo, strBomDetails, strMterialListItemInfo)
        End If

        strHtmlTable = strHtmlTable.Replace("共&nbsp;0&nbsp;页", String.Format("共&nbsp;{0}&nbsp;页", PR.PageCount))
    End Sub

    ''' <summary>
    ''' 生成表头
    ''' </summary>
    ''' <param name="tPageCount"></param>
    ''' <param name="pageCount"></param>
    ''' <param name="qty"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function SetTableTitle(ByVal tPageCount As Integer, ByVal pageCount As Integer, ByVal type As Integer, ByVal partCharacterType As String, ByVal originalstartdate As String, ByVal gys As String) As String

        Dim parttype As String = If(isselfmfg, "零件", "组件")
        If Not String.IsNullOrWhiteSpace(originalstartdate) Then
            originalstartdate = DateTime.Parse(originalstartdate).ToString("yyyy年MM月dd日")
        End If
        Dim sb As New StringBuilder()
        sb.Append("<table class=table1 >")
        sb.Append("<tr><th colspan=3 valign='bottom' style='height:60px;text-align: center;position:relative'>")
        If parttype = "零件" Then
            sb.AppendLine("<div style='width:100%;height:36px;text-align:left;position:absolute;left:0;top:0px' ><div style='float:left'>供应商:</div><span style='text-align:left;font-weight:normal;'>" + gys + "</span></div>")
        End If
        If type = 7 Then
            sb.AppendFormat("<span style=float:left;margin-top:10px>内部</span><span style=font-size:32px;>单件加工{0}工艺流水卡片</span><div style='float:right;margin-top:10px'>" + partCharacterType + "</div></th></tr>", parttype)
        Else
            sb.AppendFormat("<span style=float:left;margin-top:10px>内部</span><span style=font-size:32px;>批量加工{0}工艺流水卡片</span><div style='float:right;margin-top:10px'>" + partCharacterType + "</div></th></tr>", parttype)
        End If

        sb.AppendFormat("<tr><td style='text-align: left;padding-left:10px;'>{0}</td>", wfFactoryName) 'update:Wangjh 2017-7-6 将工厂更改为当前用户所属的 20180927更改为工艺分厂
        sb.AppendFormat("<td style='text-align: center'> {0} </td>", originalstartdate)
        sb.AppendFormat("<td style='text-align: right; padding-right:40px;'>共&nbsp;0&nbsp;页第&nbsp;{0}&nbsp;张", pageCount.ToString())
        'sb.AppendFormat("<td style='text-align: right; padding-right:40px;'>{0}/共&nbsp;0&nbsp;页第&nbsp;{1}&nbsp;张", conRemark, pageCount.ToString())
        sb.Append("</td></tr></table>")
        SetTableTitle = sb.ToString
    End Function

    ''' <summary>
    ''' 生成流水卡信息
    ''' </summary>
    ''' <param name="PR"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function SetTableMain(ByVal PR As uMESProcessResult, ByVal Originalqty As Integer) As String
        Dim dtMain As DataTable = PR.DBDataSet.Tables("dtMain")
        dtSubWorkflowstepList = PR.DBDataSet.Tables("dtSubWorkflowstepList") '各子工艺工序热表批次号 add zhunan 2022.10.27
        Dim sbHtml As New StringBuilder
        Dim productName = dtMain.Rows(0)("Productname").ToString()
        Dim ProductDesc = dtMain.Rows(0)("ProductDesc").ToString()
        Dim workflowRoute As String = dtMain.Rows(0)("workflowroute").ToString() '分段件号
        Dim familyName = dtMain.Rows(0)("familylistnames")
        Dim partRev As String = dtMain.Rows(0)("Part_RevID").ToString '设计图版次 
        Dim prosseRev As String = dtMain.Rows(0)("ly2sequence").ToString '工艺规程版次 
        Dim zhbmodel As String = dtMain.Rows(0)("zhbmodel").ToString '合并机型 
        Dim lgort As String = dtMain.Rows(0)("lgort").ToString '库存地点 
        'Modify by Yuxj20200528 型号包含WP,全通，但是不包含WP，设计图版次和工艺版次打印斜杠
        If (familyName.ToString.Contains("WP") Or familyName.ToString.Contains("全通")) And (Not familyName.ToString.Contains("WS")) And (Not familyName.ToString.Contains("KWP2")) Then
            partRev = "/"
            prosseRev = "/"
        End If

        'yuxj20221028 临时工艺字段变更，由workflowtype--->workflowtype2,内容由 临时-->临时工艺
        'Dim workflowType As String = dtMain.Rows(0)("WorkflowType").ToString '工艺类型
        Dim workflowType2 As String = dtMain.Rows(0)("WorkflowType2").ToString '工艺类型
        Dim prosseNo As String = dtMain.Rows(0)("process_no").ToString '原始工艺号

        If workflowType2.Trim <> "临时工艺" Then
            prosseNo = ""
        End If
        Dim wfFactoryID = dtMain.Rows(0)("wffactoryid").ToString()
        wfFactoryName = dtMain.Rows(0)("wffactoryname").ToString()
        bomPersonMerge = m_CommonObj.GetFatoryAttributes(wfFactoryID, "配套表人员合并")
        Dim Containername = dtMain.Rows(0)("Containername").ToString()
        strContainerName = Containername

        sbHtml.Append("<table class='table2' ><tr ><td width='110' >设计图版次</td><td width='60'>" + partRev + "</td><td width='110'>工艺规程版次</td><td width='60'>" + prosseRev + "</td><td width='120'>临时工艺规程编号</td><td>" + prosseNo + "</td></tr></table>")
        sbHtml.Append("<table class='table2'>")
        Dim dtDataPoint As DataTable = PR.DBDataSet.Tables("dtDataPoint")
        If Not String.IsNullOrWhiteSpace(workflowRoute) Then
            strProductName = workflowRoute
        End If
        If wfFactoryName.Contains("机匣") And dtDataPoint.Select("dataname='ChildWFContianer'").Length > 0 Then
            strProductName += "(H)"
        End If

        If isselfmfg Then '零件
            'sbHtml.AppendFormat("<tr><td colspan=2>生产订单号</td><td colspan=2>{0}</td><td colspan=2>批次号</td><td colspan=2>{1}</td></tr>", strMfgordername, Containername.Replace(productName + "/", ""))
            sbHtml.AppendFormat("<tr><td colspan=2>生产订单号</td><td colspan=2>{0}</td><td colspan=2>批次号</td><td colspan=2>{1}</td></tr>", strMfgordername, strFinallyShowContainername) '显示批次后缀 add zhunan 2023.1.17
            Dim Originalstartdate = dtMain.Rows(0)("Originalstartdate").ToString()
            Dim Materialtrademark = dtMain.Rows(0)("PlanMaterialtrademark").ToString '材料牌号
            Dim MaterialSpecification = dtMain.Rows(0)("PlanMaterialSpecification").ToString '材料规格
            Dim materialSize = dtMain.Rows(0)("materialSize").ToString '毛料规格
            Dim strMaterialtEmp As String = "" '库房保管
            Dim strmaterialCheckEmp As String = "" '器材检验

            Dim strFilter As String = "dataname='实发数/顺序号'"
            Dim tmpRows As DataRow() = dtDataPoint.Select(strFilter)
            Dim shifa As String = ""
            If tmpRows.Length > 0 Then
                If tmpRows(0).IsNull("datavalue") = False Then
                    shifa = tmpRows(0)("datavalue").ToString()
                End If
                If tmpRows(0).IsNull("splitfromid") = False Then '如果该批次是由分批而来的实发数就是分批数 add:Wangjh 2017-7-25
                    shifa = tmpRows(0)("originalqty").ToString()
                End If
            End If

            Dim rongluChild As String = GetDataValue(dtDataPoint, "熔炉号子")
            Dim rongluP As String = GetDataValue(dtDataPoint, "熔炉号母")
            Dim jianyan As String = GetDataValue(dtDataPoint, "检验编号")
            Dim paihao As String = GetDataValue(dtDataPoint, "代料牌号", True)
            Dim paihaoge As String = GetDataValue(dtDataPoint, "代料规格", True)
            Dim danhao As String = GetDataValue(dtDataPoint, "代料单号", True)
            Dim pingxing As String = GetDataValue(dtDataPoint, "平行作业工序", True)
            Dim pingxingBill As String = GetDataValue(dtDataPoint, "平行作业单号", True)

            strMaterialtEmp = GetDataValue(dtDataPoint, "库房保管")
            strmaterialCheckEmp = GetDataValue(dtDataPoint, "器材检验")
            sbHtml.Append("<tr><td width='90px'>零件号</td>")

            sbHtml.AppendFormat("<td width='110' id='pName'>{0}</td>", strProductName)

            sbHtml.AppendFormat("<td width='75'>名称</td><td width='120'>{0}</td>", ProductDesc)
            sbHtml.AppendFormat("<td width='55'>型别</td><td width='120' style='font-size: 12px'>{0}</td>", familyName + IIf(String.IsNullOrWhiteSpace(zhbmodel), "", "/" + zhbmodel))
            sbHtml.AppendFormat("<td width='65'>计划员</td><td width='100'>{0}</td></tr>", strPlanName)

            sbHtml.Append("<tr><td>熔炉号</td>")
            If String.IsNullOrWhiteSpace(rongluChild) And String.IsNullOrWhiteSpace(rongluP) Then
                sbHtml.Append("<td></td>")
            ElseIf String.IsNullOrWhiteSpace(rongluChild) Then
                sbHtml.AppendFormat("<td>{0}</td>", rongluP)
            ElseIf String.IsNullOrWhiteSpace(rongluP) Then
                sbHtml.AppendFormat("<td>{0}</td>", rongluChild)
            Else
                sbHtml.AppendFormat("<td style='font-size :small'>子：{0}</p>母：{1}</td>", rongluChild, rongluP)
            End If

            sbHtml.AppendFormat("<td>计划数</td><td>{0}</td>", Originalqty)
            sbHtml.AppendFormat("<td>实发数/顺序号</td><td>{0}</td>", shifa)
            sbHtml.AppendFormat("<td>工艺员</td><td>{0}</td></tr>", strTechniqueEmp)

            sbHtml.AppendFormat("<tr><td>材料牌号</td><td style='font-size: 12px'>{0}</td>", Materialtrademark)

            sbHtml.AppendFormat("<td>检&nbsp;验编&nbsp;号</td><td>{0}</td>", jianyan)
            sbHtml.AppendFormat("<td>库&nbsp;房保&nbsp;管</td><td>{0}</td>", strMaterialtEmp)
            'sbHtml.Append("<td>器&nbsp;材检&nbsp;验</td>")
            'If String.IsNullOrWhiteSpace(pingxingBill) Then
            '    sbHtml.AppendFormat("<td>{0}</td>", strmaterialCheckEmp)
            'Else
            '    sbHtml.Append("<td></td>")
            'End If
            sbHtml.AppendFormat("<td>器&nbsp;材检&nbsp;验</td><td>{0}</td>", strmaterialCheckEmp)
            sbHtml.Append("</tr>")

            sbHtml.AppendFormat("<td>材料规格</td><td style='font-size: 12px'>{0}</td>", MaterialSpecification)
            sbHtml.AppendFormat("<td>毛&nbsp;料规&nbsp;格</td><td style='font-size: 12px'>{0}</td>", materialSize)
            sbHtml.AppendFormat("<td>代&nbsp;料牌&nbsp;号</td><td>{0}</td>", paihao)
            sbHtml.AppendFormat("<td>代&nbsp;料规&nbsp;格</td><td>{0}</td></tr>", paihaoge)

            sbHtml.AppendFormat("<tr><td>代料单号</td><td>{0}</td>", danhao)
            'Modify by yuxj20200528 平行作业单->例外放行审批单号 平行作业工序->例外放行工序
            sbHtml.AppendFormat("<td>例外放行审批单号</td><td>{0}</td>", pingxingBill)
            sbHtml.AppendFormat("<td>例外放行工序</td><td>{0}</td>", pingxing) '
            sbHtml.Append("<td>分&nbsp;厂检&nbsp;验</td>")
            If dtDataPoint.Rows(0).IsNull("splitfromid") = False Then '如果该批次是由分批而来的 add:Wangjh 2017-7-25
                sbHtml.AppendFormat("<td>{0}</td>", dtDataPoint.Rows(0)("checkemployeeName").ToString())
            Else
                'sbHtml.Append("<td></td>")
                'add zhunan 2021.1.18 增加显示【分厂检验】（取第一道工序实际的检验员）
                Dim fcjy As String = ""
                If PR.DBDataSet.Tables("dtContainerStep").Columns.Contains("checkemployeename") Then
                    Dim temp = PR.DBDataSet.Tables("dtContainerStep").Select("factoryid='" + wfFactoryID + "'")
                    If temp.Length > 0 Then
                        fcjy = temp(0)("checkemployeename").ToString
                    End If
                End If
                sbHtml.AppendFormat("<td>{0}</td>", fcjy)
            End If
            sbHtml.Append("</tr>")

            'add zhunan 2021.1.18 打印顾客代表、热表批次号
            Dim gkdb As String = GetDataValue(dtDataPoint, "顾客代表")
            sbHtml.Append("<tr>")
            Dim dtRbContainerList As DataTable = PR.DBDataSet.Tables("dtRbContainerList") '热表批次号
            If dtRbContainerList.Rows.Count = 0 Then
                sbHtml.Append("<td colspan=1>热表批次</td> <td colspan=2></td> <td colspan=2></td> <td colspan=1></td>")
            ElseIf dtRbContainerList.Rows.Count = 1 Then
                sbHtml.AppendFormat("<td colspan=1>热表批次</td> <td colspan=2>{0}</td><td colspan=2></td><td colspan=1></td>", dtRbContainerList.Rows(0)("rbtogetherflag").ToString())
            ElseIf dtRbContainerList.Rows.Count = 2 Then
                sbHtml.AppendFormat("<td colspan=1>热表批次</td> <td colspan=2>{0}</td><td colspan=2>{1}</td><td colspan=1></td>",
                                    dtRbContainerList.Rows(0)("rbtogetherflag").ToString(),
                                    dtRbContainerList.Rows(1)("rbtogetherflag").ToString())
            Else
                sbHtml.AppendFormat("<td colspan=1>热表批次</td> <td colspan=2>{0}</td><td colspan=2>{1}</td><td colspan=1>{2}</td>",
                                    dtRbContainerList.Rows(0)("rbtogetherflag").ToString(),
                                    dtRbContainerList.Rows(1)("rbtogetherflag").ToString(),
                                    dtRbContainerList.Rows(2)("rbtogetherflag").ToString())
            End If

            sbHtml.AppendFormat("<td colspan=1>顾&nbsp;客代&nbsp;表</td><td colspan=1>{0}</td>", gkdb)
            sbHtml.Append("</tr>")

            '追加不合格审理单号 add by zhangrj 2022-2-23
            Dim unQualifiedNum As String = GetDataValue(dtDataPoint, "不合格审理单号", True)
            sbHtml.AppendFormat("<tr><td colspan=2>不合格审理单号</td><td colspan=3>{0}</td><td>库存地点</td><td colspan=2>{1}</td></tr>", unQualifiedNum, lgort)
        Else '组件
            sbHtml.AppendFormat("<tr><td colspan=2>生产订单号</td><td colspan=2>{0}</td><td colspan=2>库存地点</td><td colspan=2>{1}</td></tr>", strMfgordername, lgort)
            sbHtml.Append("<tr><td width='60'>组合件号</td>")

            sbHtml.AppendFormat("<td width='120' id='pName'>{0}</td>", strProductName)

            sbHtml.AppendFormat("<td width='55'>名称</td><td width='120'>{0}</td>", ProductDesc)
            sbHtml.AppendFormat("<td width='55'>型别/合并机型</td><td colspan=3 style ='font-size :10px'>{0}</td></tr>", familyName + IIf(String.IsNullOrWhiteSpace(zhbmodel), "", "/" + zhbmodel))
            'sbHtml.AppendFormat("<tr><td>批次号</td><td>{0}</td>", Containername.Replace(productName + "/", ""))
            sbHtml.AppendFormat("<tr><td>批次号</td><td>{0}</td>", strFinallyShowContainername) '显示批次后缀 add zhunan 2023.1.17
            sbHtml.AppendFormat("<td>数量</td><td>{0}</td>", Originalqty)
            sbHtml.AppendFormat("<td>计划员</td><td width='55'>{0}</td>", strPlanName)
            sbHtml.AppendFormat("<td width='55'>工艺员</td><td width='55'>{0}</td></tr>", strTechniqueEmp)
            ' sbHtml.AppendLine("<tr><td colspan=1>热表批次</td><td colspan=1></td><td colspan=2></td><td colspan=2></td><td colspan=1>顾&nbsp;客代&nbsp;表</td><td colspan=1></td></tr>")
            'sbHtml.AppendLine("<tr><td colspan=2>热表批次</td><td colspan=2></td><td colspan=2></td><td colspan=2></td></tr>")
            Dim dtRbContainerList As DataTable = PR.DBDataSet.Tables("dtRbContainerList") '热表批次号
            If dtRbContainerList.Rows.Count = 0 Then
                sbHtml.Append("<td colspan=1>热表批次</td> <td colspan=1></td> <td colspan=2></td> <td colspan=2></td>")
            ElseIf dtRbContainerList.Rows.Count = 1 Then
                sbHtml.AppendFormat("<td colspan=1>热表批次</td> <td colspan=1>{0}</td><td colspan=2></td><td colspan=2></td>", dtRbContainerList.Rows(0)("rbtogetherflag").ToString())
            ElseIf dtRbContainerList.Rows.Count = 2 Then
                sbHtml.AppendFormat("<td colspan=1>热表批次</td> <td colspan=1>{0}</td><td colspan=2>{1}</td><td colspan=2></td>",
                                    dtRbContainerList.Rows(0)("rbtogetherflag").ToString(),
                                    dtRbContainerList.Rows(1)("rbtogetherflag").ToString())
            Else
                sbHtml.AppendFormat("<td colspan=1>热表批次</td> <td colspan=1>{0}</td><td colspan=2>{1}</td><td colspan=2>{2}</td>",
                                    dtRbContainerList.Rows(0)("rbtogetherflag").ToString(),
                                    dtRbContainerList.Rows(1)("rbtogetherflag").ToString(),
                                    dtRbContainerList.Rows(2)("rbtogetherflag").ToString())
            End If
        End If

        sbHtml.Append("</table>")


        SetTableMain = sbHtml.ToString()
    End Function


    Private Function GetDataValue(ByVal dtDataPoint As DataTable, ByVal strName As String) As String
        Dim strFilter As String = "dataname='熔炉号子'"
        Dim tmpRows As DataRow() = dtDataPoint.Select(String.Format("dataname='{0}'", strName))
        GetDataValue = ""
        If tmpRows.Length > 0 Then
            If tmpRows(0).IsNull("datavalue") = False Then
                GetDataValue = tmpRows(0)("datavalue").ToString()
            End If
        End If
    End Function
    Private Function GetDataValue(ByVal dtDataPoint As DataTable, ByVal strName As String, ByVal IsDefault As Boolean) As String
        Dim strFilter As String = "dataname='熔炉号子'"
        Dim tmpRows As DataRow() = dtDataPoint.Select(String.Format("dataname='{0}'", strName))
        If IsDefault Then
            GetDataValue = "----------"
        Else
            GetDataValue = ""
        End If

        If tmpRows.Length > 0 Then
            If tmpRows(0).IsNull("datavalue") = False Then
                GetDataValue = tmpRows(0)("datavalue").ToString()
            End If
        End If
    End Function
    ''' <summary>
    ''' 生成流水卡工序
    ''' </summary> 
    ''' <param name="PR"></param>
    ''' <param name="qty"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function SetTableDetail(ByVal PR As uMESProcessResult, ByVal qty As Integer) As String
        SetTableDetail = String.Empty
        Try
            Dim dtMain As DataTable = PR.DBDataSet.Tables("dtMain")
            Dim dtContainerStep As DataTable = PR.DBDataSet.Tables("dtContainerStep")
            Dim dtCheckItemList As DataTable = PR.DBDataSet.Tables("dtCheckItemList")
            Dim conType As Integer = Val(PR.DBDataSet.Tables("dtMain").Rows(0)("CONTAINERTYPE").ToString())
            Dim wipQty = dtMain.Rows(0)("qty").ToString

            Dim strProdcut As String = dtMain.Rows(0)("productname").ToString().Trim()
            Dim strMemo As String = ""
            '得到关闭备注信息
            Dim strCloseContainer As String = ""
            If dtMain.Rows(0).IsNull("CloseContianer") = False Then
                strCloseContainer = dtMain.Rows(0)("CloseContianer").ToString().Trim()
                strMemo = oIBusiness.GetColseMemo(strCloseContainer)
            End If
            '得到开始工序
            '得到关闭备注信息
            Dim strBeginStepName As String = ""
            If dtMain.Rows(0).IsNull("BeginStep") = False Then
                strBeginStepName = dtMain.Rows(0)("BeginStep").ToString().Trim()
            End If
            ' Dim gys As String = GetDataValue(PR.DBDataSet.Tables("dtDataPoint"), "供应商", False)
            Dim sbHtml As New StringBuilder
            Dim count As Integer = 0
            Dim current As Integer = 0
            Dim specname = String.Empty
            Dim specid = String.Empty
            Dim stepid = String.Empty
            Dim sequenceNO = String.Empty
            Dim stepName As String = ""
            Dim drsCheckItemList As DataRow() = Nothing
            Dim p As Integer = 0
            Dim hight As Integer = 0
            Dim hightperrow As Integer = 30
            Dim lastCHKitemstr As String = ""
            Dim lastCHKitemIndex As Integer = 0

            Do While (p < PR.PageCount)
                count = current + 25
                If p = 0 Then
                    If isselfmfg Then
                        count = 12
                    Else
                        count = 17
                    End If
                    current = 0
                    hight = hightperrow * count
                Else
                    sbHtml.Append(SetTableTitle(PR.PageCount, p + 1, conType, "", startDate, ""))
                    hight = hightperrow * 25
                End If


                Dim curHeight As Integer = 0

                sbHtml.Append(SetTableSpecHeader(If(p = 0, True, False)))

                For i As Integer = current To count
                    Dim sbSpecHtml As New StringBuilder
                    Dim strBmemo As String = ""
                    If lastCHKitemstr.Length = 0 Then '没有上页结余数据
                        specname = String.Empty
                        specid = String.Empty
                        sequenceNO = String.Empty
                        stepName = String.Empty 'add:Wangjh 2017-8-4
                        stepid = String.Empty
                        If dtContainerStep.Rows.Count > i Then
                            SetSpecNameInfo(specname, stepid, specid, stepName, sequenceNO, dtContainerStep.Rows(i))
                            If stepName = strBeginStepName Then
                                'strBmemo = strMemo
                            End If

                            'strBmemo = dtContainerStep.Rows(i)("NOTES").ToString() + "," 'add zhunan 2022.1.18

                            ''固定外委备注显示 外委加工 add zhunan 2022.3.15
                            'If dtContainerStep.Rows(i)("CONTROLCODE").ToString() = "LY05" Or dtContainerStep.Rows(i)("ISCOMMISSION").ToString() = "1" Then
                            '    strBmemo += "外委加工,"
                            'End If
                        End If

                        '检测项
                        If dtCheckItemList.Rows.Count > 0 Then
                            drsCheckItemList = dtCheckItemList.Select(" workflowstepid='" + stepid + "'", "CheckNo")
                        End If

                        sbSpecHtml.Append(SetSpecInfo(specname, sequenceNO, stepid, wipQty, strBmemo, dtContainerStep, i, stepName))
                        curHeight += hightperrow
                    End If
                    '检测项
                    If drsCheckItemList IsNot Nothing Then
                        If drsCheckItemList.Count > 0 Then
                            Dim htmlTemp As String = ""
                            Dim lastheight As Integer = hight - curHeight
                            htmlTemp = SetCheckItemList(drsCheckItemList, sequenceNO, specname, hightperrow, lastheight, curHeight, lastCHKitemstr, lastCHKitemIndex)
                            If lastCHKitemstr.Length = 0 And lastCHKitemIndex = drsCheckItemList.Count - 1 Then
                                lastCHKitemIndex = 0
                            End If
                            If sbSpecHtml.Length > 0 Then
                                If lastCHKitemstr.Length = 0 Then '没有剩余页内容
                                    sbSpecHtml = sbSpecHtml.Replace("rowspan=1", String.Format("rowspan={0}", drsCheckItemList.Count * 2 + 1))
                                ElseIf lastheight > 0 Then
                                    sbSpecHtml = sbSpecHtml.Replace("rowspan=1", String.Format("rowspan={0}", lastCHKitemIndex * 2 + 2)) '补完合并行
                                End If
                            End If
                            sbSpecHtml.Append(htmlTemp)
                        End If

                    End If

                    sbHtml.Append(sbSpecHtml.ToString)
                    If curHeight >= hight Then
                        If dtContainerStep.Rows.Count - 1 = i Then
                            i += 1
                        End If
                        current = i
                        Exit For
                    Else
                        lastCHKitemstr = ""
                        lastCHKitemIndex = 0
                    End If

                Next
                sbHtml.Append("</table>")
                If p = 0 Then '条码绘制 create:Yangsj 2018-4-22 
                    Dim strTmp As String = strContainerName.Replace("(", "%")
                    strTmp = strTmp.Replace(")", "%")
                    If String.IsNullOrWhiteSpace(strMfgordername) Then
                        sbHtml.AppendFormat("<div style='height:70px;PAGE-BREAK-AFTER:always'><div class=barCode style='float:Right'>*{0}*</div> <div style='clear:both'></div>  </div>", strContainerID) 'creat:Wangjh 2017-7-14 modify strTmp->strContainerID
                    Else
                        sbHtml.AppendFormat("<div style='height:70px;PAGE-BREAK-AFTER:always'><div class=barCode style='float:left'>*{0}*</div> <div class=barCode style='float:Right'>*{1}*</div>  </div>", strContainerID, strMfgordername) 'creat:Wangjh 2017-6-22 modify strTmp->strContainerID
                    End If
                End If
                p += 1
                'lastCHKitemIndex = 0 'add:Wangjh 20180719
                PR.PageCount = p
                If PR.PageCount = p And dtContainerStep.Rows.Count > current + 1 Then
                    PR.PageCount += 1
                    If lastCHKitemstr.Length = 0 Then
                        current += 1
                    End If
                End If
                If PR.DBDataSet.Tables("dtBOM").Rows.Count = 0 Then 'create:2017-7-5 Wangjh
                    If PR.PageCount Mod 2 = 1 Then
                        PR.PageCount += 1
                    End If
                End If
            Loop

            SetTableDetail = sbHtml.ToString()
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    ''' <summary>
    ''' 生产工序表头
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function SetTableSpecHeader(ByVal isfirstpage As Boolean) As String
        Dim sbTable3Header As New StringBuilder
        If isfirstpage Then
            sbTable3Header.Append("<table id=originaltable class=table3 style='BORDER-TOP: medium none;'>")
        Else
            sbTable3Header.Append("<table id=originaltable class=table3 style='BORDER-TOP: medium none;PAGE-BREAK-AFTER: always'>")
        End If
        sbTable3Header.Append("<tr><td rowspan=2 width='65'><div class=t_1>工序</div></td>")
        sbTable3Header.Append("<td rowspan=2 width='150'>名称</td>")
        sbTable3Header.Append("<td rowspan=2 width='35'>数量</td>")
        sbTable3Header.Append("<td colspan=4>自检结果（件数）</td>")

        sbTable3Header.Append("<td rowspan=2 width='80'>加&nbsp;&nbsp;工日&nbsp;&nbsp;期</td>")
        sbTable3Header.Append("<td  rowspan=2 width='35' style='BORDER-RIGHT: medium none'>工</td>")
        sbTable3Header.Append("<td  rowspan=2 width='45' style='BORDER-LEFT: medium none'>人</td>")
        sbTable3Header.Append("<td rowspan=2 width='55'>检验印</td>")
        sbTable3Header.Append("<td rowspan=2 width='105'>备注</td>")
        sbTable3Header.Append("<tr><td width='30'><div class=t_2>合格</div></td>")
        sbTable3Header.Append("<td width='30'><div class=t_2>报废</div></td>")
        sbTable3Header.Append("<td width='30'><div class=t_2>超差</div></td>")
        sbTable3Header.Append("<td width='30'><div class=t_2>返修</div></td></tr>")
        SetTableSpecHeader = sbTable3Header.ToString
    End Function

    ''' <summary>
    ''' 工序基本信息处理
    ''' </summary>
    ''' <param name="specname"></param>
    ''' <param name="specid"></param>
    ''' <param name="stepName"></param>
    ''' <param name="sequenceNO"></param>
    ''' <param name="dr"></param>
    ''' <remarks></remarks>
    Private Sub SetSpecNameInfo(ByRef specname As String, ByRef stepid As String, ByRef specid As String, ByRef stepName As String, ByRef sequenceNO As String, ByVal dr As DataRow)

        specname = dr("specname").ToString()
        specid = dr("specid").ToString()
        stepName = dr("workflowstepname").ToString()
        stepid = dr("workflowstepid").ToString
        If String.IsNullOrWhiteSpace(specname) Then 'add:Wangjh 2017-8-3 
            specname = stepName
        End If

        Dim arrTemp = stepName.Split("-")
        sequenceNO = arrTemp(0)
        specname = stepName.Replace(sequenceNO + "-", "")

        If Not String.IsNullOrWhiteSpace(dr("opdesc").ToString()) Then
            specname = dr("opdesc").ToString()
        End If
        '

        'add:Wangjh 增加工序号和工序名赋值 20171206
        If Not String.IsNullOrWhiteSpace(dr("specno").ToString()) Then
            sequenceNO = dr("specno").ToString()
        End If
        '处理工序号位数
        Try
            If IsNumeric(sequenceNO) Then
                sequenceNO = Integer.Parse(sequenceNO).ToString
            End If
        Catch ex As Exception

        End Try

        '关键工序，在工序号前加G
        If dr("iskey").ToString() = "1" Then
            sequenceNO = "G" + sequenceNO
        End If
    End Sub

    ''' <summary>
    ''' 生成工序表格
    ''' </summary>
    ''' <param name="specname">工序名</param>
    ''' <param name="sequenceNO">工序号</param>
    ''' <param name="specid">工序ID</param>
    ''' <param name="wipQty">在制数</param>
    ''' <param name="strBmemo">备注</param>
    ''' <param name="dtWorkReport">报工记录</param>
    ''' <param name="dtQuality">报废记录</param>
    ''' <param name="dtLastCheck">完工记录</param>
    ''' <param name="dtConCheck">检验记录</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function SetSpecInfo(ByVal specname As String, ByVal sequenceNO As String, ByVal stepid As String, ByVal wipQty As String,
                                 ByVal strBmemo As String, ByVal dtContainerStep As DataTable, ByVal i As Integer, ByVal stepName As String) As String
        Dim sbSpecHtml As New StringBuilder
        If Not dtContainerStep.Columns.Contains("reportdate") Then
            dtContainerStep.Columns.Add("reportdate")
        End If
        '报工
        Dim drsReport As DataRow() = dtContainerStep.Select(" workflowstepid='" + stepid + "' and reportdate is not null")
        ' Dim dicField = GetDetailsField(drsReport, drsQuality, drsSpecLastCheck, drsConventionCheck)
        sbSpecHtml.AppendFormat("<tr idtype=spec  ><td rowspan=1>{0}</td><td rowspan=1 class=t_4", sequenceNO)

        If specname.Length > 15 Then
            sbSpecHtml.Append(" style='font-size: 10px'>")
        Else
            sbSpecHtml.Append(">")
        End If
        sbSpecHtml.AppendFormat("{0}</td>", specname)
        '添加检验备注 add zhangrj 20220608

        If isBlank Then
            strBmemo = ""
        Else
            If stepid <> "" Then
                Dim drsCheckNotes As DataRow() = dtContainerStep.Select("workflowstepid='" + stepid + "'")
                strBmemo += drsCheckNotes(0)("NOTES").ToString + ","

                If dtContainerStep.Columns.Contains("ISCOMMISSION") Then
                    If drsCheckNotes(0)("CONTROLCODE").ToString() = "LY05" Or drsCheckNotes(0)("ISCOMMISSION").ToString() = "1" Then
                        strBmemo += "外委加工,"
                    End If
                End If
                For Each cknote As DataRow In drsCheckNotes
                    If Not String.IsNullOrWhiteSpace(cknote("CHECKNOTE").ToString) Then
                        strBmemo += cknote("CHECKNOTE").ToString + ","
                    End If
                    If Not String.IsNullOrWhiteSpace(cknote("WORKNOTE").ToString) Then
                        strBmemo += cknote("WORKNOTE").ToString + ","
                    End If
                Next

                '如果是子工艺工序，工序备注追加显示热表批次号 add zhunan 2022.10.27
                If Not IsNothing(dtSubWorkflowstepList) Then
                    Dim drSubWorkflowstepInfos As DataRow() = dtSubWorkflowstepList.Select("workflowstepname='" + stepName + "'")
                    If drSubWorkflowstepInfos.Length > 0 Then
                        strBmemo += drSubWorkflowstepInfos(0)("RBTOGETHERFLAG").ToString() + ","
                    End If
                End If
                strBmemo = strBmemo.Trim(",")
            End If
        End If

        If drsReport.Length = 0 Then
            Dim controlCode = ""
            Dim lastCheck = ""
            If stepid <> "" Then
                If dtContainerStep.Rows(i)("CONTROLCODE").ToString = "LY05" Then
                    controlCode = "--"
                End If
                If dtContainerStep.Rows(i)("LASTCHECK").ToString = "1" Then
                    lastCheck = "--"
                End If
            End If

            If strBmemo <> "" And strBmemo.Length > 11 Then
                '固定外委 报工人、检验人显示"--"
                If controlCode <> "" Then
                    sbSpecHtml.Append("<td></td><td></td><td></td><td></td><td></td><td></td><td colspan=2>--</td><td>--</td><td style='text-align: left;font-size: 10px'>" + strBmemo + "</td>")
                ElseIf lastCheck <> "" Then '检验序 报工人显示 "--"
                    sbSpecHtml.Append("<td></td><td></td><td></td><td></td><td></td><td></td><td colspan=2>--</td><td></td><td style='text-align: left;font-size: 10px'>" + strBmemo + "</td>")
                Else
                    sbSpecHtml.Append("<td></td><td></td><td></td><td></td><td></td><td></td><td colspan=2></td><td></td><td style='text-align: left;font-size: 10px'>" + strBmemo + "</td>")
                End If
            Else
                '固定外委 报工人、检验人显示"--"
                If controlCode <> "" Then
                    sbSpecHtml.Append("<td></td><td></td><td></td><td></td><td></td><td></td><td colspan=2>--</td><td>--</td><td style='text-align: left;'>" + strBmemo + "</td>")
                ElseIf lastCheck <> "" Then '检验序 报工人显示 "--"
                    sbSpecHtml.Append("<td></td><td></td><td></td><td></td><td></td><td></td><td colspan=2>--</td><td></td><td style='text-align: left;'>" + strBmemo + "</td>")
                Else
                    sbSpecHtml.Append("<td></td><td></td><td></td><td></td><td></td><td></td><td colspan=2></td><td></td><td style='text-align: left;'>" + strBmemo + "</td>")
                End If
            End If
        Else
            Dim strTmpMemo As String = ""
            If dtContainerStep.Rows(i)("checktype").ToString = "3" Then '试验件报工
                'strTmpMemo = IIf(isBlank, "", "试件报工:" & dtContainerStep.Rows(i)("ReportQty").ToString + ",")
                'dtContainerStep.Rows(i)("ReportQty") = wipQty
                'dtContainerStep.Rows(i)("passqty") = wipQty
                'dtContainerStep.Rows(i)("lossqty") = DBNull.Value
                '试件特殊处理 update:wangjh 20220719
                strTmpMemo = IIf(isBlank, "", "试件报工:" & dtContainerStep.Rows(i)("SpecimenQty").ToString + ",")

                'add by zhangrj 20230727 如果是全试件报工，则报工数等于试件数，合格数也等于试件数（不管是否有报废）
                If dtContainerStep.Rows(i)("ReportQty").ToString() = "0" Or String.IsNullOrWhiteSpace(dtContainerStep.Rows(i)("ReportQty").ToString()) Then
                    dtContainerStep.Rows(i)("ReportQty") = dtContainerStep.Rows(i)("SpecimenQty").ToString
                    dtContainerStep.Rows(i)("passqty") = dtContainerStep.Rows(i)("SpecimenQty").ToString
                End If

                'dtContainerStep.Rows(i)("ReportQty") = dtContainerStep.Rows(i)("SpecimenQty").ToString
                'dtContainerStep.Rows(i)("passqty") = Val(dtContainerStep.Rows(i)("SpecimenQty").ToString) - Val(dtContainerStep.Rows(i)("lossqty").ToString)

            End If
            Dim reportDate As String = ""
            If Not dtContainerStep(i).IsNull("reportdate") Then
                reportDate = DateTime.Parse(dtContainerStep(i)("reportdate")).ToString("yyyy/MM/dd")
            End If

            sbSpecHtml.Append("<td>" + dtContainerStep.Rows(i)("ReportQty").ToString + "</td><td style='")
            sbSpecHtml.Append("'>" + dtContainerStep.Rows(i)("passqty").ToString + "</td><td>" + dtContainerStep.Rows(i)("lossqty").ToString + "</td>")
            sbSpecHtml.Append("<td>" + dtContainerStep.Rows(i)("defectqty").ToString + "</td><td>" + dtContainerStep.Rows(i)("ReworkQty").ToString + "</td><td>" + reportDate + "</td>")

            'If dicField("ConventionCheckNote").Trim() = "" Then
            '    strTmpMemo = strBmemo
            'ElseIf strBmemo = "" Then
            '    strTmpMemo = dicField("ConventionCheckNote")
            'Else
            '    strTmpMemo = dicField("ConventionCheckNote") + "/br" + strBmemo
            'End If

            sbSpecHtml.Append("<td colspan=2 style='")
            If dtContainerStep.Rows(i)("ReportEmployeeName").ToString.Length > 6 Then
                sbSpecHtml.Append(" font-size: 10px")
            End If

            '检验工序 报工人显示横岗 add zhunan 2022.3.15
            If dtContainerStep.Rows(i)("LASTCHECK").ToString = "1" Or dtContainerStep.Rows(i)("CONTROLCODE").ToString = "LY05" Then
                sbSpecHtml.Append("'>" + "--" + "</td><td style='")
            Else
                sbSpecHtml.Append("'>" + dtContainerStep.Rows(i)("ReportEmployeeName").ToString + "</td><td style='")
            End If

            'sbSpecHtml.Append("<td colspan=2>" + dtContainerStep.Rows(i)("ReportEmployeeName").ToString + "</td><td style='")

            If dtContainerStep.Rows(i)("CONTROLCODE").ToString = "LY05" Then
                sbSpecHtml.Append("'>" + "--" + "</td><td style='text-align: left;")
            Else
                If dtContainerStep.Rows(i)("checkemployeename").ToString.Length > 6 Then
                    sbSpecHtml.Append(" font-size: 10px")
                End If
                sbSpecHtml.Append("'>" + dtContainerStep.Rows(i)("checkemployeename").ToString + "</td><td style='text-align: left;")
            End If

            'strTmpMemo += dtContainerStep.Rows(i)("NOTES").ToString + ","

            '工序备注栏追加显示 检验员填写的备注信息 add zhunan 2022.4.24
            'If dtContainerStep.Rows(i)("CHECKNOTE").ToString <> " Then" Then
            '    strTmpMemo += dtContainerStep.Rows(i)("CHECKNOTE").ToString + ","
            'End If
            strTmpMemo += strBmemo
            strTmpMemo = strTmpMemo.Trim(",")
            If strTmpMemo.Length > 11 Then
                sbSpecHtml.Append(" font-size: 10px")
            End If
            sbSpecHtml.Append("'>" + strTmpMemo + "</td>")
        End If

        sbSpecHtml.Append("</tr>")
        Return sbSpecHtml.ToString()
    End Function

    ''' <summary>
    ''' 检测项表格生成
    ''' </summary>
    Private Function SetCheckItemList(ByVal drsCheckItemList As DataRow(), ByVal sequenceNO As String, ByVal specname As String, ByVal heightperrow As Integer, ByVal lastheight As Integer, ByRef curheight As Integer, ByRef lastitemstr As String, ByRef lastIndex As Integer) As String
        Dim sbHtml As New StringBuilder
        Dim dtImageAll As DataTable
        Session("dtImage") = dtImageAll
        Dim heighthtml As Integer = 0
        Dim strCode As String = ""
        Dim curindex = lastIndex
        Dim rowspan = 0
        For i = lastIndex To drsCheckItemList.Length - 1
            Dim note As String = ""
            If Not drsCheckItemList(i).IsNull("Notes") Then
                note = drsCheckItemList(i)("Notes").ToString
            End If
            Dim checkNo As String = ""
            If Not drsCheckItemList(i).IsNull("CheckNo") Then
                checkNo = drsCheckItemList(i)("CheckNo")
            End If
            Dim strCheckName, strCheckPointNote, strCheckPointCode As String
            Dim strPagePath As String = System.Web.HttpContext.Current.Request.Path
            dtImageAll = Session("dtImage")
            strCheckName = drsCheckItemList(i).Item("description").ToString
            If Not drsCheckItemList(i).IsNull("CHECKPOINTNOTE") Then
                strCheckPointNote = drsCheckItemList(i).Item("CHECKPOINTNOTE")
            Else
                strCheckPointNote = ""
            End If
            If Not String.IsNullOrWhiteSpace(strCheckName) Then
                strCheckPointNote = "(" + strCheckName + ")" + strCheckPointNote
            End If

            curindex += 1
            If lastheight = 0 Or lastheight = heighthtml Then '页面已无剩余空间显示直接进行截取
                strCheckPointCode = "要求: " + DataAdjust.ParseCode(strCheckPointNote, strPagePath, dtImageAll)
                lastitemstr = strCheckPointCode
                Exit For
            End If
            Dim _sbHtml As New StringBuilder
            _sbHtml.Append("<tr>")
            If lastitemstr.Length > 0 Then
                _sbHtml.AppendFormat("<td rowspan=-1>{0}</td><td rowspan=-1 class=t_4", sequenceNO)
                If specname.Length > 18 Then
                    _sbHtml.Append(" style='font-size: 12px'>")
                Else
                    _sbHtml.Append(">")
                End If
                _sbHtml.AppendFormat("{0}</td><td colspan=1 rowspan=0 >关键过程记录</td>", specname)

                strCheckPointCode = lastitemstr
                lastitemstr = ""
                If strCheckPointCode.Trim.Length = 0 Then '无剩余截取文本
                    'add by zhunnan 2022.4.7 检测项实际值显示规则：检验员录入转码 》 检验员录入未转码 》 工人录入转码 》工人录入未转码
                    Dim stepcheckpointresult = GetStepCheckPointResult(drsCheckItemList(i), strPagePath, dtImageAll)
                    _sbHtml.AppendFormat("<td>{0}</td><td class=t_3 colspan=7>实际：{1}</td><td></td></tr>", checkNo, stepcheckpointresult)
                    sbHtml.Append(_sbHtml.ToString)
                    rowspan += 1
                    heighthtml += heightperrow
                    Continue For
                End If
            Else
                If i = lastIndex Then
                    _sbHtml.AppendFormat("<td rowspan=0 >关键过程记录</td>")
                End If
                strCheckPointCode = "要求: " + DataAdjust.ParseCode(strCheckPointNote, strPagePath, dtImageAll)
                Session("dtImage") = dtImageAll.Copy
            End If
            _sbHtml.AppendFormat("<td rowspan=2>{0}</td>", checkNo) 'modify:Wangjh 20180507 checkNo->strCheckName

            Dim itemheight As Integer = GetStrHeight(strCheckPointCode, 310, lastheight - heighthtml, lastitemstr)

            If lastitemstr.Length > 0 Then '将截取的文本显示出来 add zhangrj 20240108 
                strCheckPointCode = strCheckPointCode + lastitemstr
                Dim h As Integer = (lastitemstr.Length / 21) + 1
                itemheight = itemheight + h * 30
                lastitemstr = ""
            End If

            If itemheight > heightperrow Then
                itemheight = Math.Ceiling(itemheight / heightperrow) * heightperrow
            Else
                itemheight = heightperrow
            End If
            heighthtml += itemheight
            _sbHtml.AppendFormat("<td colspan=7 ><div class=t_3 style='height:{1}px;'>{0}</div></td><td></td></tr>", strCheckPointCode, itemheight)
            rowspan += 1
            If lastheight = heighthtml And String.IsNullOrWhiteSpace(lastitemstr) Then
                lastitemstr = ""
            End If

            'add by zhunnan 2022.4.7 检测项实际值显示规则：检验员录入转码 》 检验员录入未转码 》 工人录入转码 》工人录入未转码
            Dim stepcheckpointresult1 = GetStepCheckPointResult(drsCheckItemList(i), strPagePath, dtImageAll)
            _sbHtml.AppendFormat("<tr><td class=t_3 colspan=7>实际：{0}</td><td></td></tr>", stepcheckpointresult1)
            heighthtml += heightperrow
            rowspan += 1
            '注释掉截取字段的判断 add by zhangrj 20240108
            'If lastitemstr.Length > 0 Then
            '    _sbHtml = _sbHtml.Replace("rowspan=2", "rowspan=1") '按工序合并
            '    sbHtml.Append(_sbHtml.ToString)
            '    Exit For
            'Else
            '    'add by zhunnan 2022.4.7 检测项实际值显示规则：检验员录入转码 》 检验员录入未转码 》 工人录入转码 》工人录入未转码
            '    Dim stepcheckpointresult = GetStepCheckPointResult(drsCheckItemList(i), strPagePath, dtImageAll)
            '    _sbHtml.AppendFormat("<tr><td class=t_3 colspan=7>实际：{0}</td><td></td></tr>", stepcheckpointresult)
            '    heighthtml += heightperrow
            '    rowspan += 1
            'End If
            sbHtml.Append(_sbHtml.ToString)
        Next
        sbHtml = sbHtml.Replace("rowspan=0", String.Format("rowspan={0}", rowspan)) '按检测项合并
        sbHtml = sbHtml.Replace("rowspan=-1", String.Format("rowspan={0}", rowspan)) '按工序合并

        lastIndex = curindex - 1
        If heighthtml = 30 Then
            sbHtml = sbHtml.Replace(">关键过程记录", "style='font-size: 11px'>关键过程记录")
        End If
        curheight += heighthtml
        SetCheckItemList = sbHtml.ToString()
    End Function

    ''' <summary>
    ''' 计算文本内容高度，并截取
    ''' </summary>
    ''' <param name="strValue"></param>
    ''' <param name="width"></param>
    ''' <param name="lastitemheight"></param>
    ''' <param name="strlast"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetStrHeightOld(ByRef strValue As String, ByVal width As Integer, ByVal lastitemheight As Integer, ByRef strlast As String) As Integer
        Dim totalLength = CharacterLen(strValue)
        Dim hsindex As New DataTable
        hsindex.Columns.Add("index", GetType(Integer))
        hsindex.Columns.Add("imgValue")
        hsindex.Columns.Add("ImgRealLen", GetType(Integer))
        Dim tempValue = strValue
        Dim tempIdx = 0
        Dim widthchar As Integer = Math.Ceiling(width / 7) '行最大字符数
        '过滤图片img字串
        Do While (Not String.IsNullOrWhiteSpace(tempValue))
            Dim intidx = tempValue.IndexOf("<img")
            If intidx < 0 Then
                tempValue = ""
            Else
                tempValue = tempValue.Substring(intidx)
                tempIdx += intidx
                Dim imgValue = tempValue.Substring(0, tempValue.IndexOf("png'>") + 5)
                Dim imgpath As String = ConfigurationManager.AppSettings("ImageTempSavePath") + imgValue.Substring(imgValue.IndexOf("<img src=../../../ImageTemp/") + 29).Replace("'>", "")
                Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(imgpath)
                Dim realLen As Integer = Math.Ceiling(img.Width / 7)
                totalLength = totalLength - imgValue.Length + realLen '图片格式默认站8个字符
                hsindex.Rows.Add(tempIdx, imgValue, realLen)

                tempValue = tempValue.Substring(4)
                tempIdx += 4
            End If
        Loop

        GetStrHeightOld = Math.Ceiling(totalLength / widthchar) * 15 '获取实际高度 文本长度/表格长度*单行文字高度
        If GetStrHeightOld > lastitemheight Then
            Dim Index As Integer = 0 '截取文本起始位置
            Dim Row As Integer = Math.Ceiling(lastitemheight / 15) '行数
            For ridx As Integer = 1 To Row
                Dim exidx As Integer = Index + widthchar
                Dim haspic As Boolean = False
                Dim exstr = ""
                If strValue.Length > exidx Then
                    exstr = strValue.Substring(Index, If(strValue.Length > exidx, strValue.Length - Index, widthchar)) '本行字符
                Else
                    exstr = strValue.Substring(Index)
                End If
                Dim i_len = Len(exstr)
                For i_index = 1 To i_len
                    Index += 1
                    Dim ascint = Asc(Mid(exstr, i_index, 1))
                    If ascint > 0 And ascint < 65 Then '判断汉字和大写字母
                        Continue For
                    ElseIf ascint > 90 Then
                        Continue For
                    End If
                    exidx -= 1
                    If exidx = Index Then
                        Exit For
                    End If
                Next

                For Each hsr As DataRow In hsindex.Rows
                    Dim key As Integer = hsr("index")
                    Dim realLen As Integer = hsr("ImgRealLen")
                    tempIdx = key + hsr("imgValue").ToString.Length '获取图片长度

                    If tempIdx < Index Then '已处理图片
                        Continue For
                    End If
                    If key > exidx Then
                        Continue For

                    End If
                    If tempIdx <= exidx Then '图片长度完全包含在截取位置
                        exidx = exidx + hsindex(key).ToString.Length - realLen
                        haspic = True
                    Else
                        If exidx - key >= realLen Then '图片实际长度完全包含在截取位置
                            exidx = tempIdx + exidx - key - realLen
                            haspic = True
                        Else
                            exidx = key '长度不够直接换行
                            Exit For
                        End If
                    End If
                Next
                Index = exidx

                If haspic Then
                    ridx += 1
                End If
            Next

            Index -= 7 '需减去行默认值‘要求：’长度7
            If strValue.Length < Index Then
                Index = strValue.Length
            End If
            strlast = strValue.Substring(Index)
            strValue = strValue.Substring(0, Index)


            If String.IsNullOrWhiteSpace(strlast) Then
                strlast = " " '无剩余待截取文本
            End If
            GetStrHeightOld = lastitemheight

        End If

    End Function


    Private Function GetStrHeight(ByRef strValue As String, ByVal width As Integer, ByVal lastitemheight As Integer, ByRef strlast As String) As Integer

        Dim strIndex As String = ""
        Dim i_len As Integer = Len(strValue) '字符数
        Dim widthchar As Integer = Math.Ceiling(width / 7) '行最大字符数
        Dim hsindex As DataTable = GetImgTable(strValue, widthchar)
        Dim Row As Integer = Math.Ceiling(lastitemheight / 15) '行数
        Dim CurRow As Integer = 0 '当前行数
        Dim CurRowWidth As Integer = 0 '当前行宽度字符
        Dim imgrow As DataRow()
        Dim hasrowimg As Boolean = False '本行是否有图片
        Dim rowimgcount As Integer = 0 '有图片的行数
        For i_index = 1 To i_len
            If CurRowWidth = 0 Then
                CurRowWidth = widthchar
            End If
            Dim strMid = Mid(strValue, i_index, 1)
            Dim ascint = Asc(StrConv(strMid, VbStrConv.SimplifiedChinese))
            Dim realLen As Integer

            realLen = System.Text.Encoding.Unicode.GetByteCount(strMid)

            'If ascint > 0 And ascint < 58 Then '判断数字
            '    realLen = 1
            'ElseIf ascint > 96 And ascint < 123 Then '判断小写字母
            '    realLen = 1
            'Else '判断汉字和大写字母
            '    realLen = 2
            'End If
            imgrow = hsindex.Select(String.Format("index={0}", i_index - 1))
            If imgrow.Length = 1 Then '存在图片
                realLen = imgrow(0)("ImgRealLen")
                If realLen > widthchar Then '图片超过表格宽度
                    realLen = widthchar
                End If

                strMid = imgrow(0)("imgValue")
                hasrowimg = True
            End If

            If CurRowWidth >= realLen Then
                CurRowWidth -= realLen
                If strMid.Length > 1 Then
                    i_index += strMid.Length - 1
                End If
                strIndex += strMid
            Else '行剩余长度不够,直接换行
                CurRowWidth = 0
                i_index -= 1 '索引后退
            End If

            If CurRowWidth = 0 Or i_index >= i_len Then
                If hasrowimg Then
                    rowimgcount += 1
                End If
                CurRow += 1
                hasrowimg = False
            End If

            If CurRow + Math.Ceiling(rowimgcount / 2) = Row Then '当前行等于总行数，即停止截取
                Exit For
            End If
        Next
        CurRow += Math.Ceiling(rowimgcount / 2)
        strlast = strValue.Replace(strIndex, "")
        strValue = strIndex
        GetStrHeight = CurRow * 15
    End Function

    Private Function GetImgTable(ByVal tempValue As String, ByVal widthchar As Integer) As DataTable
        GetImgTable = New DataTable
        GetImgTable.Columns.Add("index", GetType(Integer))
        GetImgTable.Columns.Add("imgValue")
        GetImgTable.Columns.Add("ImgRealLen", GetType(Integer))
        Dim tempIdx = 0
        '过滤图片img字串
        Do While (Not String.IsNullOrWhiteSpace(tempValue))
            Dim intidx = tempValue.IndexOf("<img")
            If intidx < 0 Then
                tempValue = ""
            Else
                tempValue = tempValue.Substring(intidx)
                tempIdx += intidx
                Dim imgValue = tempValue.Substring(0, tempValue.IndexOf("png'>") + 5)
                Dim imgpath As String = ConfigurationManager.AppSettings("ImageTempSavePath") + imgValue.Substring(imgValue.IndexOf("<img src=../../../ImageTemp/") + 29).Replace("'>", "")
                Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(imgpath)
                Dim realLen As Integer = Math.Ceiling(img.Width / 7)
                GetImgTable.Rows.Add(tempIdx, imgValue, realLen)
                tempValue = tempValue.Substring(4)
                tempIdx += 4
            End If
        Loop

    End Function
    ''' <summary>
    ''' 获取字符串长度
    ''' </summary>
    ''' <param name="s_str"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function CharacterLen(ByVal s_str As String) As Integer

        Dim i_num As Integer
        Dim i_index As Integer
        Dim i_len As Integer

        i_len = Len(s_str)

        For i_index = 1 To i_len
            Dim ascint = Asc(Mid(s_str, i_index, 1))
            If ascint > 0 And ascint < 65 Then '判断汉字和大写字母
                Continue For
            ElseIf ascint > 90 Then
                Continue For
            End If
            i_num = i_num + 1
        Next

        CharacterLen = i_len + i_num

    End Function

    '为每个工序确定报工信息和检验信息
    Function GetDetailsField(ByVal drsReport As DataRow(), ByVal drsQuality As DataRow(), ByVal drsSpecLastCheck As DataRow(),
                             ByVal drsConventionCheck As DataRow()) As Dictionary(Of String, String)
        '报工
        Dim qty = 0
        Dim reportDate = ""
        Dim worker = ""
        For j = 0 To drsReport.Count - 1
            If j = 0 Then
                reportDate = DateTime.Parse(drsReport(j)("reportdate")).ToString("yyyy/MM/dd") 'update:Wangjh txndate改为reportdate
                worker = drsReport(j)("ReportEmployeeName").ToString() 'update:Wangjh fullname改为ReportEmployeeName
            End If
            Try
                qty = qty + Convert.ToInt32(drsReport(j)("qty"))
            Catch

            End Try
        Next

        '报废
        Dim qtyBaoFei = 0
        Dim qtyChaoCha = 0
        Dim qtyFanxiu = 0
        Dim qtyHeGe = 0
        Dim checkmam = ""

        If drsQuality.Count = 0 Then
            Try
                checkmam = drsSpecLastCheck(0)("fullname")
            Catch ex As Exception

            End Try

        End If
        For j = 0 To drsQuality.Count - 1

            If Not drsQuality(0).IsNull("fullname") Then 'add:wangjh 2017-7-31增加判断
                checkmam = drsQuality(0)("fullname")
            End If

            Try
                qtyBaoFei = qtyBaoFei + drsQuality(j)("lossqty") '结构件数据'update:Wangjh 201707028
                If drsQuality(j)("qualitydisposeadvicename") = "报废" Then
                    qtyBaoFei = qtyBaoFei + Convert.ToInt32(drsQuality(j)("qty"))
                End If

            Catch
            End Try
            Try
                qtyChaoCha = qtyChaoCha + drsQuality(j)("defectqty") '结构件数据'update:Wangjh 201707028
                If drsQuality(j)("qualitydisposeadvicename") = "超差" Then
                    qtyChaoCha = qtyChaoCha + Convert.ToInt32(drsQuality(j)("qty"))
                End If
            Catch

            End Try
            Try
                If drsQuality(j)("qualitydisposeadvicename") = "返修" Then
                    qtyFanxiu = qtyFanxiu + Convert.ToInt32(drsQuality(j)("qty"))
                End If
            Catch

            End Try
        Next
        qtyHeGe = qty - qtyFanxiu - qtyBaoFei - qtyChaoCha
        Dim dicField As New Dictionary(Of String, String)

        dicField.Add("qty", If(qty = 0, "", qty.ToString()))
        dicField.Add("qtyBaoFei", If(qtyBaoFei = 0, "", qtyBaoFei.ToString()))
        dicField.Add("qtyChaoCha", If(qtyChaoCha = 0, "", qtyChaoCha.ToString))
        dicField.Add("qtyFanxiu", If(qtyFanxiu = 0, "", qtyFanxiu.ToString))
        dicField.Add("qtyHeGe", If(qtyHeGe = 0, "", qtyHeGe.ToString))
        dicField.Add("reportDate", reportDate)
        dicField.Add("worker", worker)
        dicField.Add("checkmam", checkmam)

        If drsConventionCheck.Length > 0 Then
            dicField.Add("ConventionCheckNote", If(drsConventionCheck(0).IsNull("notes"), "", drsConventionCheck(0)("notes").ToString().Trim))
        Else
            dicField.Add("ConventionCheckNote", "")
        End If

        If drsReport.Length > 0 Then '试验件报工 add:Wangjh 20180105
            If drsReport(0)("checktype").ToString() = "3" Then
                dicField.Add("TestReport", "1")
            End If
        End If
        Return dicField
    End Function

    ''' <summary>
    ''' 配套表
    ''' </summary>
    ''' <param name="PR"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function SetBomDetail(ByVal PR As uMESProcessResult) As String
        SetBomDetail = String.Empty
        Dim dtMain As DataTable = PR.DBDataSet.Tables("dtMain")
        Dim dtBom As DataTable = PR.DBDataSet.Tables("dtBom")
        Dim dtIssue As DataTable = PR.DBDataSet.Tables("dtIssue") 'add:Wangjh 20180109
        Dim noUseRow As Integer = 0
        '若完成集件配套后需要减去的行数 add:Wangjh 20180117
        'Dim tempView As DataView = dtIssue.Copy.DefaultView
        'tempView.RowFilter = "ISSUEQTY is not null"
        'Dim tempDt As DataTable = tempView.ToTable
        'noUseRow = tempDt.Rows.Count - tempView.ToTable(True, "WorkFLowStepID").Rows.Count
        '

        If dtBom.Rows.Count = 0 Then 'Create:2017-7-5 Wangjh
            Exit Function
        End If
        dtBom.Columns.Add("sequenceNO", Type.GetType("System.String"))

        For r As Integer = 0 To dtBom.Rows.Count - 1
            Dim dr = dtBom.Rows(r)
            Dim specname = dr("specname").ToString()
            Dim sequenceNO = ""
            Dim arrTemp = specname.Split("-")
            If arrTemp.Length = 2 Then
                sequenceNO = specname.Split("-")(0)
            ElseIf arrTemp.Length = 3 Then
                sequenceNO = specname.Split("-")(1)
            End If

            'dtBom.Rows.Add()
            'add:Wangjh 增加工序和工序号重新赋值 20171206
            If Not String.IsNullOrWhiteSpace(dr("specno").ToString()) Then
                sequenceNO = dr("specno").ToString()
            End If
            If Not String.IsNullOrWhiteSpace(dr("opdesc").ToString()) Then
                specname = dr("opdesc").ToString()
            End If
            '
            If IsNumeric(sequenceNO) Then
                sequenceNO = Integer.Parse(sequenceNO).ToString
            End If
            dr("sequenceNO") = sequenceNO
        Next

        Dim dtpBomTemp As DataTable = dtBom.Copy()
        Dim dv As DataView = dtBom.DefaultView
        dtpBomTemp = dv.ToTable()
        Dim col As New DataColumn
        col.ColumnName = "IsSpan"
        col.DefaultValue = 0
        dtpBomTemp.Columns.Add(col)
        dtpBomTemp.AcceptChanges()
        Try
            Dim Originalqty = dtMain.Rows(0)("Originalqty").ToString()
            Dim Containername = dtMain.Rows(0)("Containername").ToString()
            Dim productName = dtMain.Rows(0)("Productname").ToString()
            Dim page = PR.PageCount + Math.Ceiling(dtpBomTemp.Rows.Count / 24)

            Dim sb As New StringBuilder()
            If Originalqty = 1 Then
                If page Mod 2 = 1 Then
                    page += 1
                End If
            End If
            page = page - PR.PageCount
            PR.PageCount += page
            Dim count As Integer = 24
            Dim current As Integer = 0
            If Originalqty > 1 Then 'create:Wangjh 2017-6-27
                If page Mod 2 = 1 Then
                    page += 1
                End If
            End If

            For p As Integer = 1 To page
                sb.Append("<table class=table1>")
                sb.Append("<tr><th colspan=3 style=text-align: center>")
                sb.Append("<span style=font-size:32px;>组合件配套表</span></th></tr>")
                sb.Append("<tr><td style='text-align: left;padding-left:10px;'>生产订单号：" + strMfgordername + "</td>")
                sb.Append("<td style='text-align: center'>组合件号：" + strProductName + "</td>")
                sb.Append("<td style='text-align: right; padding-right:40px;'>组合件批次号: " + Containername.Replace(productName + "/", "") + " </td>")
                sb.Append("</tr></table>")
                sb.Append("<table id=originaltable class=table3>")
                sb.Append("<tr idtype=head><td width=30><div class=t_1>工序号</div></td>")
                sb.Append("<td width=130>零件号</td>")
                sb.Append("<td width=30>单台数量</td>")
                sb.Append("<td width=30>发出数量</td>")
                '  sb.Append("<td width=140>熔炉号</td>") update:Wangjh 2017-6-22
                sb.Append("<td width=130>批次号</td>")
                sb.Append("<td width=80>更换件批次号</td>")
                sb.Append("<td width=50>配套者</td>")
                sb.Append("<td width=50>领用人</td>")
                sb.Append("<td width=50>检验员</td>")
                sb.Append("<td width=50>是否有不合格品审理单</td>") 'creat:Wangjh 2017-6-22
                sb.Append("<td width=35>备注</td></tr>")

                count = current + 24 - noUseRow

                For i As Integer = current To count
                    current = i
                    If dtpBomTemp.Rows.Count <= i Then
                        sb.Append("<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>")

                        Continue For
                    End If
                    Dim dr = dtpBomTemp.Rows(i)
                    Dim qty As Double = Double.Parse(dr("qtyrequired").ToString)

                    Dim SpanCount = 1
                    If dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString = "1" Then
                        SpanCount = GetSpanCount(dr("SPECNO").ToString, dr("ProductName").ToString, dtpBomTemp, i, count)
                    ElseIf bomPersonMerge = "是" Then
                        SpanCount = GetSpanCount(dr("SPECNO").ToString, dtpBomTemp, i, count)
                    End If

                    '如果BOM类型是批次（序列号）
                    Dim sequene As String = ""
                    If dtpBomTemp.Rows(i)("IsSpan") = 1 And dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString = "1" Then

                    Else
                        If dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString = "1" And SpanCount > 1 Then
                            sb.AppendFormat("<tr><td rowspan={0}>" + dtpBomTemp.Rows(i)("sequenceNO").ToString + "</td>", SpanCount)
                            If dr("productname").ToString().Trim().Length < 14 Then
                                sb.AppendFormat("<td rowspan={0}>" + dtpBomTemp.Rows(i)("productname") + "</td>", SpanCount)
                            Else
                                sb.AppendFormat("<td rowspan={0} style='text-align: center;font-size: 10px'>" + dtpBomTemp.Rows(i)("productname") + "</td>", SpanCount)
                            End If
                            sb.AppendFormat("<td rowspan={0}>" + qty.ToString() + "</td>", SpanCount)
                            sb.AppendFormat("<td rowspan={0} >" + "" + "</td>", SpanCount)
                        Else
                            sb.Append("<tr><td>" + dr("sequenceNO").ToString + "</td>")
                            If dr("productname").ToString().Trim().Length < 14 Then
                                sb.Append("<td>" + dr("productname") + "</td>")
                            Else
                                sb.Append("<td style='text-align: center;font-size: 10px'>" + dr("productname") + "</td>")
                            End If
                            sb.Append("<td>" + qty.ToString() + "</td>")
                            'add:Wangjh 取实际发出数
                            'Dim fachuQty As String = dtIssue.Compute("sum(ISSUEQTY)", String.Format("specid='{0}'", dr("specid").ToString)).ToString
                            Dim fachuQty As String = ""
                            '
                            'sb.Append("<td>" + (qty * Integer.Parse(Originalqty)).ToString + "</td>") 
                            sb.Append("<td>" + fachuQty.ToString + "</td>")
                        End If
                    End If
                    '

                    'If dtpBomTemp.Rows(i)("IsSpan") = 1 Then
                    '    sb.Append("<td></td><td></td><td></td><td></td>")
                    'Else
                    '    If SpanCount > 1 Then
                    '        sb.AppendFormat("<td></td><td></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td><td></td><td></td>", SpanCount)
                    '    Else
                    '        sb.Append("<td></td><td></td><td></td><td></td><td></td><td></td><td></td>")
                    '    End If
                    'End If
                    If dtpBomTemp.Rows(i)("IsSpan") = 1 And dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString = "1" Then
                        sb.AppendFormat("<td></td><td></td><td></td>")
                    ElseIf dtpBomTemp.Rows(i)("IsSpan") = 1 And dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString <> "1" And bomPersonMerge = "是" Then
                        sb.Append("<td></td><td></td><td></td><td></td>")
                    Else
                        If SpanCount > 1 And dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString <> "1" And bomPersonMerge = "是" Then
                            sb.AppendFormat("<td></td><td></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan=1></td><td></td>", SpanCount)
                        Else
                            sb.AppendFormat("<td></td><td></td><td></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td>", SpanCount)
                        End If
                    End If
                    sb.Append("</tr>")
                Next
                sb.Append("</table>")
                current = current + 1
            Next
            'If Originalqty = 1 Then
            SetBomDetail = sb.ToString
            'Else
            '    'Dim strSplitInfo = SetSplitInfo(PR) 'create:Wangjh 2017-6-22
            '    SetBomDetail = sb.ToString
            'End If
        Catch ex As Exception

        End Try
    End Function

    ''' <summary>
    ''' 配套表新横向
    ''' </summary>
    ''' <param name="PR"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function SetBomDetailNew(ByVal PR As uMESProcessResult) As String
        SetBomDetailNew = String.Empty
        Dim dtMain As DataTable = PR.DBDataSet.Tables("dtMain")
        Dim dtBom As DataTable = PR.DBDataSet.Tables("dtBom")
        Dim dtContainerStep As DataTable = PR.DBDataSet.Tables("dtContainerStep")
        Dim dtIssue As DataTable = PR.DBDataSet.Tables("dtIssue") 'add:Wangjh 20180109

        If dtBom.Rows.Count = 0 And dtIssue.Rows.Count = 0 Then
            Return ""
        End If
        'If dtBom.Rows.Count = 0 Then
        '    dtBom = dtIssue
        'End If

        strMfgordername = dtMain.Rows(0)("Mfgordername").ToString
        Dim wfFactoryID = dtMain.Rows(0)("wffactoryid").ToString()
        bomPersonMerge = m_CommonObj.GetFatoryAttributes(wfFactoryID, "配套表人员合并")
        '集件配套后增加的行数
        If Not dtBom.Columns.Contains("PRODUCTCHILDNO") Then
            dtBom.Columns.Add(New DataColumn("PRODUCTCHILDNO"))
        End If
        If Not dtBom.Columns.Contains("fullname") Then
            dtBom.Columns.Add(New DataColumn("fullname"))
        End If
        If Not dtBom.Columns.Contains("TOPRODUCTCHILDNO") Then
            dtBom.Columns.Add(New DataColumn("TOPRODUCTCHILDNO"))
        End If

        If Not dtBom.Columns.Contains("ISSUEQTY") Then
            Dim tempCol As DataColumn = New DataColumn("ISSUEQTY")
            tempCol.DataType = System.Type.GetType("System.Decimal")
            dtBom.Columns.Add(tempCol)
        End If

        '

        '加载当前bom和历史集件信息

        Dim dtpBomTemp As DataTable = dtBom.Clone
        For r As Integer = 0 To dtBom.Rows.Count - 1
            Dim dr = dtBom.Rows(r)

            ' 
            '集件信息
            Dim issueDrs As DataRow() = dtIssue.Select(String.Format("ISSUEQTY is not null and SPECNO='{0}' and opdesc='{1}' and productname='{2}'",
                                                                     dr("SPECNO").ToString, dr("opdesc").ToString, dr("productname").ToString))
            If issueDrs.Length = 0 Then
                dtpBomTemp.ImportRow(dr)
                Continue For
            End If
            For issueNum As Integer = 0 To issueDrs.Length - 1
                dr("ISSUEQTY") = issueDrs(issueNum)("ISSUEQTY")
                dr("PRODUCTCHILDNO") = issueDrs(issueNum)("PRODUCTCHILDNO")
                dr("fullname") = issueDrs(issueNum)("fullname")
                dr("TOPRODUCTCHILDNO") = issueDrs(issueNum)("TOPRODUCTCHILDNO")
                dr("note") = issueDrs(issueNum)("note")
                dtpBomTemp.ImportRow(dr)
            Next
            '
        Next

        '加载bom中无，但集件信息表有的数据 add:Wangjh 20230302
        For Each issueRow In dtIssue.Rows
            If dtBom.Select(String.Format("SPECNO='{0}' and opdesc='{1}' and productname='{2}'",
                                                                     issueRow("SPECNO").ToString, issueRow("opdesc").ToString, issueRow("productname").ToString)).Length = 0 Then
                dtpBomTemp.ImportRow(issueRow)
            End If
        Next

        If dtpBomTemp.Rows.Count > 0 Then
            dtpBomTemp = dtpBomTemp.AsEnumerable().OrderBy(Function(p) p("SPECNO").ToString()).ThenBy(Function(p) p("productname").ToString()).CopyToDataTable() '新增排序 add by zhangrj 20230512
        End If

        'Dim dv As DataView = dtpBomTemp.DefaultView
        'dv.Sort = "specno asc"
        'dtpBomTemp = dv.ToTable
        'Dim dv As DataView = dtBom.DefaultView
        'dtpBomTemp = dv.ToTable()
        Dim col As New DataColumn
        col.ColumnName = "IsSpan"
        col.DefaultValue = 0
        dtpBomTemp.Columns.Add(col)
        dtpBomTemp.AcceptChanges()
        Try
            Dim Originalqty = dtMain.Rows(0)("Originalqty").ToString()
            Dim Containername = dtMain.Rows(0)("Containername").ToString()
            Dim productName = dtMain.Rows(0)("Productname").ToString()

            Dim page = 0

            If dtpBomTemp.Rows.Count > 15 Then
                page = PR.PageCount + Math.Ceiling((dtpBomTemp.Rows.Count - 15) / 17) + 1
            Else
                page = PR.PageCount + 1
            End If

            Dim sb As New StringBuilder()
            If Originalqty = 1 Then
                If page Mod 2 = 1 Then
                    page += 1
                End If
            End If
            page = page - PR.PageCount
            PR.PageCount += page
            Dim count As Integer = 16
            Dim current As Integer = 0
            If Originalqty > 1 Then 'create:Wangjh 2017-6-27
                If page Mod 2 = 1 Then
                    page += 1
                End If
            End If

            For p As Integer = 1 To page
                sb.Append("<div style='width:960px;")
                If IsRotate Then
                    sb.Append("height:960px")
                End If
                sb.Append("'>")
                sb.Append("<div style='width:960px;")
                If IsRotate Then
                    sb.Append("filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3)")
                End If
                sb.Append("'>")
                sb.Append("<table class=table1 style='width:100%'>")
                sb.Append("<tr><th colspan=3 style=text-align: center>")
                sb.Append("<div style='text-align:left;margin-bottom:-25px;margin-top:20px'>公开</div><span style=font-size:32px;>组合件配套表</span></th></tr>")
                sb.Append("<tr><td style='text-align: left;padding-left:10px;'>生产订单号：" + strMfgordername + "</td>")
                sb.Append("<td style='text-align: center'>组合件号：" + strProductName + "</td>")
                'sb.Append("<td style='text-align: right; padding-right:40px;'>组合件批次号: " + Containername.Replace(productName + "/", "") + " </td>")
                sb.Append("<td style='text-align: right; padding-right:40px;'>组合件批次号: " + strFinallyShowContainername + " </td>")
                sb.Append("</tr></table>")
                sb.Append("<table id=originaltable class=table3 style='width:100%'>")
                sb.Append("<tr idtype=head><td width=50><div class=t_1>工序号</div></td>")
                sb.Append("<td width=170>零件号</td>")
                sb.Append("<td width=270>名称</td>")
                sb.Append("<td width=50><div class=t_1>单台数</div></td>")
                sb.Append("<td width=50><div class=t_1>发出数</div></td>")
                '  sb.Append("<td width=140>熔炉号</td>") update:Wangjh 2017-6-22
                sb.Append("<td width=140>批次号</td>")
                sb.Append("<td width=200>炉号</td>")
                sb.Append("<td width=90>换件<br>批次号</td>")
                sb.Append("<td width=100>配套者</td>")
                sb.Append("<td width=100>领用人</td>")
                sb.Append("<td width=100>检验员</td>")
                sb.Append("<td width=80>是否有不合格品审理单</td>") 'creat:Wangjh 2017-6-22
                sb.Append("<td width=130>备注</td></tr>")
                If p = 1 Then
                    count = 14
                Else
                    count = current + 16
                End If

                For i As Integer = current To count
                    current = i
                    If (dtpBomTemp.Rows.Count) <= i Then
                        sb.Append("<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>")

                        Continue For
                    End If
                    Dim dr = dtpBomTemp.Rows(i)
                    ' Dim qty As Integer = Integer.Parse(dr("qtyrequired").ToString)

                    Dim SpanCount = 1
                    If dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString = "1" Then
                        SpanCount = GetSpanCount(dr("SPECNO").ToString, dr("ProductName").ToString, dtpBomTemp, i, count)
                    ElseIf bomPersonMerge = "是" Then
                        SpanCount = GetSpanCount(dr("SPECNO").ToString, dtpBomTemp, i, count)
                    End If

                    'Dim stepRecord As DataRow() = dtContainerStep.Select("specname='" + dr("specname").ToString + "'")
                    Dim stepRecord As DataRow() = dtContainerStep.Select(String.Format("SPECNO='{0}'", dr("SPECNO").ToString()))

                    If String.IsNullOrWhiteSpace(dr("fullname").ToString()) Then 'add by zhangrj 20231030 如果当前没有配套人，则取同工序有配套人的数据
                        'Dim drFullname = dtpBomTemp.Select(String.Format("SPECNO='{0}' and fullname <> ''", dr("SPECNO").ToString()))
                        'If drFullname.Length > 0 Then
                        '    dr("fullname") = drFullname(0)("fullname").ToString()
                        'End If
                    End If

                    SetBowRow(sb, dr, SpanCount, dr, stepRecord)

                    ''如果BOM类型是批次（序列号）
                    'If dtpBomTemp.Rows(i)("IsSpan") = 1 And dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString = "1" Then

                    'Else
                    '    If dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString = "1" And SpanCount > 1 Then
                    '        sb.AppendFormat("<tr><td rowspan={0}>" + dtpBomTemp.Rows(i)("sequenceNO").ToString + "</td>", SpanCount)
                    '        If dr("productname").ToString().Trim().Length < 16 Then
                    '            sb.AppendFormat("<td rowspan={0}>" + dtpBomTemp.Rows(i)("productname") + "</td>", SpanCount)
                    '        Else
                    '            sb.AppendFormat("<td rowspan={0} style='text-align: center;font-size: 10px'>" + dtpBomTemp.Rows(i)("productname") + "</td>", SpanCount)
                    '        End If
                    '        If dr("description").ToString().Trim().Length < 21 Then
                    '            sb.AppendFormat("<td rowspan={0} >" + dtpBomTemp.Rows(i)("description").ToString + "</td><td rowspan={0}>" + qty.ToString() + "</td>", SpanCount)
                    '        Else
                    '            sb.AppendFormat("<td rowspan={0} style='text-align: center;font-size: 10px'>" + dtpBomTemp.Rows(i)("description").ToString + "</td><td rowspan={0}>" + qty.ToString() + "</td>", SpanCount)
                    '        End If

                    '        sb.AppendFormat("<td rowspan={0} >" + "" + "</td>", SpanCount)
                    '    Else
                    '        sb.Append("<tr><td>" + dr("sequenceNO").ToString + "</td>")
                    '        If dr("productname").ToString().Trim().Length < 16 Then
                    '            sb.Append("<td>" + dr("productname") + "</td>")
                    '        Else
                    '            sb.Append("<td style='text-align: center;font-size: 10px'>" + dr("productname") + "</td>")
                    '        End If
                    '        If dr("description").ToString().Trim().Length < 21 Then
                    '            sb.AppendFormat("<td rowspan=1 >" + dtpBomTemp.Rows(i)("description").ToString + "</td><td rowspan=1>" + qty.ToString() + "</td>", SpanCount)
                    '        Else
                    '            sb.AppendFormat("<td rowspan=1 style='text-align: center;font-size: 10px'>" + dtpBomTemp.Rows(i)("description").ToString + "</td><td rowspan=1>" + qty.ToString() + "</td>", SpanCount)
                    '        End If
                    '        'add:Wangjh 取实际发出数
                    '        'Dim fachuQty As String = dtIssue.Compute("sum(ISSUEQTY)", String.Format("specid='{0}'", dr("specid").ToString)).ToString
                    '        Dim fachuQty As String = ""
                    '        '
                    '        'sb.Append("<td>" + (qty * Integer.Parse(Originalqty)).ToString + "</td>") 
                    '        sb.Append("<td>" + fachuQty.ToString + "</td>")
                    '    End If
                    'End If

                    'If dtpBomTemp.Rows(i)("IsSpan") = 1 And dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString = "1" Then
                    '    sb.AppendFormat("<td></td><td></td><td></td>")
                    'ElseIf dtpBomTemp.Rows(i)("IsSpan") = 1 And dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString <> "1" And bomPersonMerge = "是" Then
                    '    sb.Append("<td></td><td></td><td></td><td></td><td></td>")
                    'Else
                    '    If SpanCount > 1 And dtpBomTemp.Rows(i)("MATERIALTXNLOGIC").ToString <> "1" And bomPersonMerge = "是" Then
                    '        sb.AppendFormat("<td></td><td></td><td></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td><td></td><td></td>", SpanCount)
                    '    Else
                    '        sb.AppendFormat("<td></td><td></td><td></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td>", SpanCount)
                    '    End If
                    'End If
                    sb.Append("</tr>")
                Next
                sb.Append("</table>")
                current = current + 1
                If p = 1 Then '第一页
                    If String.IsNullOrWhiteSpace(strMfgordername) Then
                        sb.AppendFormat("<div> <div class=barCode style='float:Right'>*{0}*</div> <div style='clear:both'></div> </div>", strContainerID) 'creat:Wangjh 2017-7-14 modify strTmp->strContainerID
                    Else
                        sb.AppendFormat("<div><div class=barCode style='float:left'>*{0}*</div> <div class=barCode style='float:Right'>*{1}*</div> <div style='clear:both'></div>  </div>", strContainerID, strMfgordername) 'creat:Wangjh 2017-6-22 modify strTmp->strContainerID
                    End If
                End If

                sb.Append("</div>")
                sb.Append("</div>")
                sb.Append("<div style='page-break-after:always'></div>") '此处强行分页
            Next
            'If Originalqty = 1 Then
            SetBomDetailNew = sb.ToString
            'Else
            '    'Dim strSplitInfo = SetSplitInfo(PR) 'create:Wangjh 2017-6-22
            '    SetBomDetail = sb.ToString
            'End If
        Catch ex As Exception

        End Try
    End Function

    Sub SetBowRow(ByRef sb As StringBuilder, ByVal dr As DataRow, ByVal SpanCount As Integer, ByVal issueDr As DataRow, ByVal stepRecord As DataRow())
        Dim fachuQty As String = "" '发出数
        Dim productChildNo As String = "" '批次号
        Dim ToProductChildNo As String = "" '换件批次号
        Dim matcher As String = "" '配套者
        Dim reportName As String = "" '领用人 取得报工人
        Dim checkName As String = "" '检验员
        If stepRecord.Length > 0 And isBlank = False Then
            reportName = stepRecord(0)("reportemployeename").ToString
            checkName = stepRecord(0)("checkemployeename").ToString
        End If
        If issueDr IsNot Nothing Then
            fachuQty = issueDr("ISSUEQTY").ToString
            productChildNo = issueDr("PRODUCTCHILDNO").ToString
            ToProductChildNo = issueDr("TOPRODUCTCHILDNO").ToString
            matcher = issueDr("fullname").ToString
        End If
        If dr("IsSpan") = 1 And dr("MATERIALTXNLOGIC").ToString = "1" Then

        Else
            If dr("MATERIALTXNLOGIC").ToString = "1" And SpanCount > 1 Then
                sb.AppendFormat("<tr><td rowspan={0}>" + dr("specno").ToString + "</td>", SpanCount)
                If dr("productname").ToString().Trim().Length < 16 Then
                    sb.AppendFormat("<td rowspan={0}>" + dr("productname") + "</td>", SpanCount)
                Else
                    sb.AppendFormat("<td rowspan={0} style='text-align: center;font-size: 10px'>" + dr("productname") + "</td>", SpanCount)
                End If
                If dr("description").ToString().Trim().Length < 21 Then
                    sb.AppendFormat("<td rowspan={0} >" + dr("description").ToString + "</td><td rowspan={0}>" + dr("qtyrequired").ToString + "</td>", SpanCount)
                Else
                    sb.AppendFormat("<td rowspan={0} style='text-align: center;font-size: 10px'>" + dr("description").ToString + "</td><td rowspan={0}>" + dr("qtyrequired").ToString + "</td>", SpanCount)
                End If

                sb.AppendFormat("<td rowspan={0} >" + fachuQty + "</td>", SpanCount)
            Else
                sb.Append("<tr><td>" + dr("specno").ToString + "</td>")
                If dr("productname").ToString().Trim().Length < 16 Then
                    sb.Append("<td>" + dr("productname") + "</td>")
                Else
                    sb.Append("<td style='text-align: center;font-size: 10px'>" + dr("productname") + "</td>")
                End If
                If dr("description").ToString().Trim().Length < 21 Then
                    sb.AppendFormat("<td rowspan=1 >" + dr("description").ToString + "</td><td rowspan=1>" + dr("qtyrequired").ToString + "</td>", SpanCount)
                Else
                    sb.AppendFormat("<td rowspan=1 style='text-align: center;font-size: 10px'>" + dr("description").ToString + "</td><td rowspan=1>" + dr("qtyrequired").ToString + "</td>", SpanCount)
                End If
                'sb.Append("<td>" + (qty * Integer.Parse(Originalqty)).ToString + "</td>") 
                sb.Append("<td>" + fachuQty + "</td>")
            End If
        End If

        Dim notes As String = ""
        If dr("productname").ToString = "13010003" Or dr("productname").ToString = "13010005" Then
            notes = "<span style='font-size:12px'>替换<br/>13010004_____件</span>"
        Else
            notes = dr("bzinfo").ToString 'modify zhunnan 2022.1.18 
        End If
        notes += issueDr("NOTE").ToString  'add:Wangjh 20230317

        If dr("IsSpan") = 1 And dr("MATERIALTXNLOGIC").ToString = "1" Then
            sb.AppendFormat("<td></td><td></td><td></td>")
        ElseIf dr("IsSpan") = 1 And dr("MATERIALTXNLOGIC").ToString <> "1" And bomPersonMerge = "是" Then
            sb.AppendFormat("<td>{0}</td><td></td><td>{1}</td><td>{2}</td><td>{3}</td>", productChildNo, ToProductChildNo, "", notes)
        Else
            Dim matcherSize As String = ""
            If matcher.Length > 3 Then
                matcherSize = "text-align: center;font-size: 10px"
            End If
            If SpanCount > 1 And dr("MATERIALTXNLOGIC").ToString <> "1" And bomPersonMerge = "是" Then
                ' sb.AppendFormat("<td></td><td></td><td></td><td rowspan={0}></td><td rowspan={0}></td><td rowspan={0}></td><td></td><td></td>", SpanCount)
                'modify zhunan 2021.7.27 配套表在备注一栏增加显示‘限制使用’
                sb.AppendFormat("<td>{1}</td><td></td><td>{2}</td><td rowspan={0} style='{4}'>{3}</td><td rowspan={0}>{6}</td><td rowspan={0}>{7}</td><td></td><td>{5}</td>", SpanCount, productChildNo, ToProductChildNo, matcher, matcherSize, notes, reportName, checkName)

            Else
                sb.AppendFormat("<td>{1}</td><td></td><td>{2}</td><td rowspan={0} style='{4}'>{3}</td><td rowspan={0}>{6}</td><td rowspan={0}>{7}</td><td rowspan={0}></td><td rowspan={0}>{5}</td>", SpanCount, productChildNo, ToProductChildNo, matcher, matcherSize, notes, reportName, checkName)
            End If
        End If


    End Sub

    ''' <summary>
    ''' 合并配套表单元格
    ''' </summary>
    ''' <param name="sequence"></param>
    ''' <param name="bomDt"></param>
    ''' <param name="sIndex"></param>
    ''' <param name="eIndex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetSpanCount(ByVal sequence As String, ByRef bomDt As DataTable, ByVal sIndex As Integer, ByVal eIndex As Integer) As Integer
        Dim count = 0
        For i As Integer = sIndex To eIndex
            If bomDt.Rows.Count - 1 < i Then
                Exit For
            End If
            If bomDt.Rows(i)("specno").ToString = sequence Then
                count += 1
                If count > 1 Then
                    bomDt.Rows(i)("IsSpan") = 1
                End If
            Else
                Exit For
            End If
        Next
        bomDt.AcceptChanges()
        Return count
    End Function

    ''' <summary>
    ''' 合并配套表零件号单元格
    ''' </summary>
    ''' <param name="sequence"></param>
    ''' <param name="bomDt"></param>
    ''' <param name="sIndex"></param>
    ''' <param name="eIndex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetSpanCount(ByVal sequence As String, ByVal productName As String, ByRef bomDt As DataTable, ByVal sIndex As Integer, ByVal eIndex As Integer) As Integer
        Dim count = 0
        For i As Integer = sIndex To eIndex
            If bomDt.Rows.Count - 1 < i Then
                Exit For
            End If
            If bomDt.Rows(i)("specno").ToString = sequence And bomDt.Rows(i)("productName").ToString = productName Then
                count += 1
                If count > 1 Then
                    bomDt.Rows(i)("IsSpan") = 1
                End If
            Else
                Exit For
            End If
        Next
        bomDt.AcceptChanges()
        Return count
    End Function

    ''' <summary>
    ''' 分批记录
    ''' </summary>
    ''' <param name="PR"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function SetSplitInfo(ByVal PR As uMESProcessResult) As String
        SetSplitInfo = String.Empty
        Dim dtSplitInfo As DataTable = PR.DBDataSet.Tables("dtSplitInfo") 'add:Wangjh 2017-7-27
        Dim dtMain As DataTable = PR.DBDataSet.Tables("dtMain")
        Try
            Dim Containername = dtMain.Rows(0)("Containername").ToString()
            Dim page = PR.PageCount + 1

            Dim sb As New StringBuilder()

            If page Mod 2 = 1 Then
                page += 1
            End If
            page = page - PR.PageCount
            Dim count As Integer = 27
            Dim current As Integer = 0
            Dim splitCount As Integer = 0
            For p As Integer = 1 To page
                sb.Append("<table id=originaltable class=table3  style='PAGE-BREAK-AFTER: always'>")
                sb.Append("<tr style='text-align: left;font-size: 18px'><td width=25 rowspan=29><div class=t_1>分批记录</div></td>")
                sb.Append("<td width=140>分批工序</td>")
                sb.Append("<td width=130>分批编号</td>")
                sb.Append("<td width=60>件数</td>")
                sb.Append("<td width=90>计划员</td>")
                sb.Append("<td width=90>检验员</td>")
                sb.Append("<td width=140>分批原因</td></tr>")
                For i As Integer = current To count
                    If splitCount < dtSplitInfo.Rows.Count Then 'add:Wangjh 201707027 增加分批数据填入
                        sb.AppendFormat(" <tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td>",
                                        dtSplitInfo.Rows(i)("workflowstepname"), dtSplitInfo.Rows(i)("splitcontainername"), dtSplitInfo.Rows(i)("qty"),
                                        dtSplitInfo.Rows(i)("splitemployeeName"), dtSplitInfo.Rows(i)("checkemployeeName"), dtSplitInfo.Rows(i)("splitreason"))
                        splitCount += 1
                    Else
                        sb.Append("<tr><td></td><td></td><td></td><td></td><td></td><td></td>")
                        sb.Append("</tr>")
                    End If
                Next

                sb.Append("</table>")

            Next
            SetSplitInfo = sb.ToString
        Catch ex As Exception

        End Try
    End Function

    ''' <summary>
    ''' 限制信息表打印 add zhunan 2021.7.28
    ''' </summary>
    ''' <param name="PR"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function SetMaterialListItemInfo(ByVal PR As uMESProcessResult) As String
        SetMaterialListItemInfo = String.Empty
        Dim dtMain As DataTable = PR.DBDataSet.Tables("dtMain")
        Dim dtIssue As DataTable = PR.DBDataSet.Tables("dtIssue")
        Dim sb As StringBuilder = New StringBuilder()
        For Each dr As DataRow In dtIssue.Rows
            If dr("print_status").ToString <> "1" Then
                Continue For
            End If
            sb.Append("<table class='table1'>")
            sb.Append("<tr><td>")
            sb.Append("<div style='font-size: 32px; font-weight: bold; text-align: center !important; height: 60px;line-height: 60px;'>限制使用单</div>")
            sb.Append("<div style='font-size: 15px; height: 20px; line-height: 20px; text-align: left; position: relative;'>")
            sb.Append("  <span style='margin-left: 10px;'>编号：</span> <span></span><span style='position: absolute; top: 0; right: 40px;'>LY-2958</span>")
            sb.Append("</div>")
            sb.Append("</td></tr></table>")

            sb.Append("<table class='table3'>")
            sb.Append("<tr><td colspan='8' style='font-size: 50px; letter-spacing: 0.5em; height: 110px; line-height: 110px;font-weight: bold;'>限制使用</td></tr>")

            sb.Append("<tr>")
            sb.Append("<td style='width: 120px;'>零件图号</td>")
            sb.AppendFormat("<td style='width: 120px;text-align: left; text-indent: 10px;'>{0}</td>", dr("PRODUCTNAME"))
            sb.Append("<td style='width: 60px;'>型 别</td>")
            sb.AppendFormat("<td style='width: 120px;'>{0}</td>", dtMain.Rows(0)("familylistnames"))
            sb.Append("<td style='width: 60px;'>技术员</td>")
            sb.Append("<td style='width: 60px;'></td>")
            sb.Append("<td style='width: 60px;'>审 核</td>")
            sb.Append("<td style='width: 60px;'></td>")
            sb.Append("</tr>")

            sb.Append("<tr>")
            sb.Append("<td>零件名称</td>")
            sb.AppendFormat("<td style='text-align: left; text-indent: 10px;'>{0}</td>", dr("description"))
            sb.Append("<td>批 次</td>")
            sb.AppendFormat("<td>{0}</td>", dr("PRODUCTCHILDNO"))
            sb.Append("<td>数 量</td>")
            sb.AppendFormat("<td>{0}</td>", dr("QTYREQUIRED"))
            sb.Append("<td>计划员</td>")
            sb.Append("<td></td>")
            sb.Append("</tr>")

            sb.Append("<tr>")
            sb.Append("<td>依据设计文件号</td>")
            sb.AppendFormat("<td colspan='7' style='text-align: left; text-indent: 10px;'>{0}</td>", dr("yjwjh"))
            sb.Append("</tr>")

            sb.Append("<tr>")
            sb.Append("<td>主要内容</td>")
            sb.AppendFormat("<td colspan='7'><div class='info'>{0}</div></td>", dr("zynr"))
            sb.Append("</tr>")

            sb.Append("<tr>")
            sb.Append("<td>执行情况</td>")
            sb.Append("<td colspan='7'><div class='xzxx'></div></td>")
            sb.Append("</tr>")

            sb.Append("<tr>")
            sb.Append("<td colspan='3'>检验员</td>")
            sb.Append("<td colspan='5'>（盖章）</td>")
            sb.Append("</tr>")

            sb.Append("<tr>")
            sb.Append("<td>限制使用信息</td>")
            sb.Append("<td colspan='7'>")
            sb.Append("<div class='xzxx'>")
            If Not String.IsNullOrEmpty(dr("xzsy").ToString) Then
                Dim strList = dr("xzsy").Split("\\n")
                For Each p As String In strList
                    If p = "n " Then
                        Continue For
                    End If
                    sb.AppendFormat("<p class='content'>{0}</p>", p.Replace("n", ""))
                Next
            Else
            End If
            sb.Append("</div>")
            sb.Append("</td>")
            sb.Append("</tr>")

            sb.Append("<tr>")
            sb.Append("<td>备注</td>")
            sb.Append("<td colspan='7'><div class='info'></div></td>")
            sb.Append("</tr>")

            sb.Append("</table>")
        Next
        SetMaterialListItemInfo = sb.ToString
    End Function

    ''' <summary>
    ''' 检测项实际值 add zhunan 2022.4.7
    ''' </summary>
    ''' <param name="dr"></param>
    ''' <param name="strPagePath"></param>
    ''' <param name="dtImageAll"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetStepCheckPointResult(ByVal dr As DataRow, ByVal strPagePath As String, ByVal dtImageAll As DataTable) As String
        Dim stepcheckpointresult As String = ""
        If dr("checkpointresultnotedis").ToString() <> "" Then
            stepcheckpointresult = dr("checkpointresultnotedis").ToString()
        ElseIf dr("checkpointresultnote").ToString <> "" Then
            stepcheckpointresult = DataAdjust.ParseCode(dr("checkpointresultnote").ToString(), strPagePath, dtImageAll)
        ElseIf dr("workcheckpointresultnotedis").ToString <> "" Then
            stepcheckpointresult = dr("workcheckpointresultnotedis").ToString()
        ElseIf dr("workcheckpointresultnote").ToString <> "" Then
            stepcheckpointresult = DataAdjust.ParseCode(dr("workcheckpointresultnote").ToString(), strPagePath, dtImageAll)
        End If
        GetStepCheckPointResult = stepcheckpointresult
    End Function

#End Region

End Class
